<?php
/*
File: categories.php
Version: 2.0
Date created: 
Last Edited : 26-07-2008
Author: Craig G Smith<craig@joomla-host.co.za
*/

  defined( 'JOSCOM_VERSION' ) or die( 'Direct Access to this location is not allowed.' );
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      tep_db_connect() or die('Unable to connect to database server!');
    }
    global $category_links, $languages_id, $cPath, $cPath_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    require(DIR_WS_COMPONENT . 'includes/application_top.php');
  }

  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  $action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : '');

  if (tep_not_null($action)) {
    switch ($action) {
      case 'setflag':
        if ( ($_REQUEST['flag'] == '0') || ($_REQUEST['flag'] == '1') ) {
          if (isset($_REQUEST['pID'])) {
            tep_set_product_status($_REQUEST['pID'], $_REQUEST['flag']);
          }

          if (USE_CACHE == 'true') {
            tep_reset_cache_block('categories');
            tep_reset_cache_block('also_purchased');
          }
        }

        tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $_REQUEST['cPath'] . '&page='.$GET['page'].'&pID=' . $_REQUEST['pID']));
        break;
       // BOF:  added by OSC-Affiliate add-on authorized products
      case 'set_affiliate_allow_flag':
        if ( ($_REQUEST['affiliate_allow_product'] == '0') || ($_REQUEST['affiliate_allow_product'] == '1') ) {
          if (isset($_REQUEST['pID'])) {
		  	$query = "UPDATE products SET affiliate_allow_product=".$_REQUEST['affiliate_allow_product']." WHERE products_id=".$_REQUEST['pID']."";
			tep_db_query($query);
		  }

          if (USE_CACHE == 'true') {
            tep_reset_cache_block('categories');
            tep_reset_cache_block('also_purchased');
          }
        }
        tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $_GET['cPath'] . '&pID=' . $REQUEST['pID']));
        break;
// EOF:  added by OSC-Affiliate add-on authorized products 
        
        
      case 'insert_category':
      case 'update_category':
        if (isset($_POST['categories_id'])) $categories_id = tep_db_prepare_input($_POST['categories_id']);

        // BOF Separate Pricing Per Customer, hide categories from groups
        $hide_cats_from_these_groups = '@,';
          if ( $_POST['hide_cat'] ) { // if any of the checkboxes are checked
		        foreach($_POST['hide_cat'] as $val) {
		        $hide_cats_from_these_groups .= tep_db_prepare_input($val).','; 
		        } // end foreach
	        }
				 $hide_cats_from_these_groups = substr($hide_cats_from_these_groups,0,strlen($hide_cats_from_these_groups)-1); // remove last comma

        $sort_order = tep_db_prepare_input($_POST['sort_order']);

        $sql_data_array = array('sort_order' => (int)$sort_order,
				 'categories_hide_from_groups' => $hide_cats_from_these_groups);
// EOF Separate Pricing Per Customer, hide categories from groups

        if ($action == 'insert_category') {
          $insert_sql_data = array('parent_id' => $current_category_id,
                                   'date_added' => 'now()');

          $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

          tep_db_perform(TABLE_CATEGORIES, $sql_data_array);

          $categories_id = tep_db_insert_id();
        } elseif ($action == 'update_category') {
          $update_sql_data = array('last_modified' => 'now()');

          $sql_data_array = array_merge($sql_data_array, $update_sql_data);

          tep_db_perform(TABLE_CATEGORIES, $sql_data_array, 'update', "categories_id = '" . (int)$categories_id . "'");
        }

        $languages = tep_get_languages();
        for ($i=0, $n=sizeof($languages); $i<$n; $i++) {

          $categories_name_array = $_POST['categories_name'];
          $categories_description_array = $_POST['categories_description'];

          $language_id = $languages[$i]['id'];

          $sql_data_array = array('categories_name' => tep_db_prepare_input($categories_name_array[$language_id]),
                                  'categories_description' => tep_db_prepare_input($categories_description_array[$language_id]));

          if ($action == 'insert_category') {
            $insert_sql_data = array('categories_id' => $categories_id,
                                     'language_id' => $languages[$i]['id']);

            $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

            tep_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array);
          } elseif ($action == 'update_category') {
            tep_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array, 'update', "categories_id = '" . (int)$categories_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'");
          }
        }

        if ($categories_image = new upload('categories_image', DIR_FS_CATALOG_IMAGES)) {
          tep_db_query("update " . TABLE_CATEGORIES . " set categories_image = '" . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'");
          AddWatermark($categories_image->filename);
        }

        if (USE_CACHE == 'true') {
          tep_reset_cache_block('categories');
          tep_reset_cache_block('also_purchased');
        }

        tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories_id));
        break;
      case 'delete_category_confirm':
        if (isset($_POST['categories_id'])) {
          $categories_id = tep_db_prepare_input($_POST['categories_id']);

          $categories = tep_get_category_tree($categories_id, '', '0', '', true);
          $products = array();
          $products_delete = array();

          for ($i=0, $n=sizeof($categories); $i<$n; $i++) {
            $product_ids_query = tep_db_query("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$categories[$i]['id'] . "'");

            while ($product_ids = tep_db_fetch_array($product_ids_query)) {
              $products[$product_ids['products_id']]['categories'][] = $categories[$i]['id'];
            }
          }

          reset($products);
          while (list($key, $value) = each($products)) {
            $category_ids = '';

            for ($i=0, $n=sizeof($value['categories']); $i<$n; $i++) {
              $category_ids .= "'" . (int)$value['categories'][$i] . "', ";
            }
            $category_ids = substr($category_ids, 0, -2);

            $check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$key . "' and categories_id not in (" . $category_ids . ")");
            $check = tep_db_fetch_array($check_query);
            if ($check['total'] < '1') {
              $products_delete[$key] = $key;
            }
          }

// removing categories can be a lengthy process
          tep_set_time_limit(0);
          for ($i=0, $n=sizeof($categories); $i<$n; $i++) {
            tep_remove_category($categories[$i]['id']);
          }

          reset($products_delete);
          while (list($key) = each($products_delete)) {
            tep_remove_product($key);
          }
        }

        if (USE_CACHE == 'true') {
          tep_reset_cache_block('categories');
          tep_reset_cache_block('also_purchased');
        }

        tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath));
        break;
      case 'delete_product_confirm':
        if (isset($_POST['products_id']) && isset($_POST['product_categories']) && is_array($_POST['product_categories'])) {
          $product_id = tep_db_prepare_input($_POST['products_id']);
          $product_categories = $_POST['product_categories'];

          for ($i=0, $n=sizeof($product_categories); $i<$n; $i++) {
            tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "' and categories_id = '" . (int)$product_categories[$i] . "'");
            tep_db_query("delete from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . tep_db_input($product_id) . "' ");
          }

          $product_categories_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'");
          $product_categories = tep_db_fetch_array($product_categories_query);

          if ($product_categories['total'] == '0') {
            tep_remove_product($product_id);
          }
        }

        if (USE_CACHE == 'true') {
          tep_reset_cache_block('categories');
          tep_reset_cache_block('also_purchased');
        }

        tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath));
        break;
      case 'move_category_confirm':
        if (isset($_POST['categories_id']) && ($_POST['categories_id'] != $_POST['move_to_category_id'])) {
          $categories_id = tep_db_prepare_input($_POST['categories_id']);
          $new_parent_id = tep_db_prepare_input($_POST['move_to_category_id']);

          $path = explode('_', tep_get_generated_category_path_ids($new_parent_id));

          if (in_array($categories_id, $path)) {
            $messageStack->add_session(ERROR_CANNOT_MOVE_CATEGORY_TO_PARENT, 'error');

            tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories_id));
          } else {
            tep_db_query("update " . TABLE_CATEGORIES . " set parent_id = '" . (int)$new_parent_id . "', last_modified = now() where categories_id = '" . (int)$categories_id . "'");

            if (USE_CACHE == 'true') {
              tep_reset_cache_block('categories');
              tep_reset_cache_block('also_purchased');
            }

            tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $new_parent_id . '&cID=' . $categories_id));
          }
        }

        break;
      case 'move_product_confirm':
        $products_id = tep_db_prepare_input($_POST['products_id']);
        $new_parent_id = tep_db_prepare_input($_POST['move_to_category_id']);

        $duplicate_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$products_id . "' and categories_id = '" . (int)$new_parent_id . "'");
        $duplicate_check = tep_db_fetch_array($duplicate_check_query);
        if ($duplicate_check['total'] < 1) tep_db_query("update " . TABLE_PRODUCTS_TO_CATEGORIES . " set categories_id = '" . (int)$new_parent_id . "' where products_id = '" . (int)$products_id . "' and categories_id = '" . (int)$current_category_id . "'");

        if (USE_CACHE == 'true') {
          tep_reset_cache_block('categories');
          tep_reset_cache_block('also_purchased');
        }

        tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $new_parent_id . '&pID=' . $products_id));
        break;
      case 'insert_product':
      case 'update_product':
        if (isset($_POST['edit_x']) || isset($_POST['edit_y'])) {
          $action = 'new_product';
        } else {
          if (isset($_REQUEST['pID'])) $products_id = tep_db_prepare_input($_REQUEST['pID']);
          $products_date_available = tep_db_prepare_input($_POST['products_date_available']);

          $products_date_available = (date('Y-m-d') < $products_date_available) ? $products_date_available : 'null';
          // BOF Separate Pricing Per Customer, hide products and categories from groups
    $hide_from_these_groups = '@,';
             if ( $_POST['hide'] ) { // if any of the checkboxes are checked
		           foreach($_POST['hide'] as $val) {
		           $hide_from_these_groups .= tep_db_prepare_input($val).','; 
		           } // end foreach
	           }
    $hide_from_these_groups = substr($hide_from_these_groups,0,strlen($hide_from_these_groups)-1); // remove last comma
// EOF Separate Pricing Per Customer, hide products and categories from groups

          $sql_data_array = array('products_quantity' => (int)tep_db_prepare_input($_POST['products_quantity']),
                                  'products_model' => tep_db_prepare_input($_POST['products_model']),
                                  //MVS start
                                  'vendors_prod_id' => tep_db_prepare_input($_POST['vendors_prod_id']),
                                  'vendors_product_price' => tep_db_prepare_input($_POST['vendors_product_price']),
                                  'vendors_id' => tep_db_prepare_input($_POST['vendors_id']),
                                  'vendors_prod_comments' => tep_db_prepare_input($_POST['vendors_prod_comments']),
                                  'supplier_id' => tep_db_prepare_input($_POST['vendors_id']),
                                  //MVS end
                                  'products_price' => tep_db_prepare_input($_POST['products_price']),
								  'Featured_Product' => tep_db_prepare_input($_POST['Featured_Product']),	
								  'products_price1' => tep_db_prepare_input($_POST['products_price1']),
                                  'products_price2' => tep_db_prepare_input($_POST['products_price2']),
                                  'products_price3' => tep_db_prepare_input($_POST['products_price3']),
                                  'products_price4' => tep_db_prepare_input($_POST['products_price4']),
                                  'products_price5' => tep_db_prepare_input($_POST['products_price5']),
                                  'products_price6' => tep_db_prepare_input($_POST['products_price6']),
                                  'products_price7' => tep_db_prepare_input($_POST['products_price7']),
                                  'products_price8' => tep_db_prepare_input($_POST['products_price8']),
                                  'products_price1_qty' => (($i=tep_db_prepare_input($_POST['products_price1_qty'])) < 0) ? 0 : $i,
                                  'products_price2_qty' => (($i=tep_db_prepare_input($_POST['products_price2_qty'])) < 0) ? 0 : $i,
                                  'products_price3_qty' => (($i=tep_db_prepare_input($_POST['products_price3_qty'])) < 0) ? 0 : $i,
                                  'products_price4_qty' => (($i=tep_db_prepare_input($_POST['products_price4_qty'])) < 0) ? 0 : $i,
                                  'products_price5_qty' => (($i=tep_db_prepare_input($_POST['products_price5_qty'])) < 0) ? 0 : $i,
                                  'products_price6_qty' => (($i=tep_db_prepare_input($_POST['products_price6_qty'])) < 0) ? 0 : $i,
                                  'products_price7_qty' => (($i=tep_db_prepare_input($_POST['products_price7_qty'])) < 0) ? 0 : $i,
                                  'products_price8_qty' => (($i=tep_db_prepare_input($_POST['products_price8_qty'])) < 0) ? 0 : $i,
                                  'products_qty_blocks' => (($i=tep_db_prepare_input($_POST['products_qty_blocks'])) < 1) ? 1 : $i,
                                  'products_date_available' => $products_date_available,
                                  'products_weight' => (float)tep_db_prepare_input($_POST['products_weight']),
                                  'products_status' => tep_db_prepare_input($_POST['products_status']),
                                  'products_tax_class_id' => tep_db_prepare_input($_POST['products_tax_class_id']),
                                  
                                  
                                  
                                  'manufacturers_id' => (int)tep_db_prepare_input($_POST['manufacturers_id']),
                                  'affiliate_allow_product' => tep_db_prepare_input($_POST['affiliate_allow_product']),
'products_length' => tep_db_prepare_input($_POST['products_length']),
  		      'products_width' => tep_db_prepare_input($_POST['products_width']),
  		      'products_hide_from_groups' => $hide_from_these_groups,
		      'products_depth' => tep_db_prepare_input($_POST['products_depth']),
		      'suppliers_id' => tep_db_prepare_input($_POST['products_suppliers_id']));
		      
		      if($_POST['pay_period'] !== ''){
$days_as_period = $_POST['pay_period'];
}else{
$days_as_period = $_POST['days_as_period'];
}
          $sql_data_array1 = array('price_period' => tep_db_prepare_input($_POST['price_period']),
                                   'oneday_price' => tep_db_prepare_input($_POST['oneday_price']),
                                   'days_as_period' => tep_db_prepare_input($days_as_period),
                                   'pay_period_type' => tep_db_prepare_input($_POST['pay_period_type']));

          if (isset($_POST['products_image']) && tep_not_null($_POST['products_image']) && ($_POST['products_image'] != 'none')) {
            $sql_data_array['products_image'] = tep_db_prepare_input($_POST['products_image']);
            }
            
            if (isset($_POST['products_vidupload']) && tep_not_null($_POST['products_vidupload']) && ($_POST['products_vidupload'] != 'none')) {
   $sql_data_array['products_vidupload'] = tep_db_prepare_input($_POST['products_vidupload']);
  }
  
  if (isset($_POST['products_mp3']) && tep_not_null($_POST['products_mp3']) && ($_POST['products_mp3'] != 'none')) {
   $sql_data_array['products_mp3'] = tep_db_prepare_input($_POST['products_mp3']);
  }
  
  if (isset($_POST['products_pdfupload']) && tep_not_null($_POST['products_pdfupload']) && ($_POST['products_pdfupload'] != 'none')) {
   $sql_data_array['products_pdfupload'] = tep_db_prepare_input($_POST['products_pdfupload']);
  }
  
  if (isset($_POST['products_fileupload']) && tep_not_null($_POST['products_fileupload']) && ($_POST['products_fileupload'] != 'none')) {
   $sql_data_array['products_fileupload'] = tep_db_prepare_input($_POST['products_fileupload']);
  }
          

          if ($action == 'insert_product') {
           // $insert_sql_data = array('products_date_added' => 'now()');
           $insert_sql_data = array('products_date_added' => 'now()', 'cost_price' => '1');

            $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

            tep_db_perform(TABLE_PRODUCTS, $sql_data_array);
            $products_id = tep_db_insert_id();
            
            $sud_data_array = array_merge($products_id, $sql_data_array1);
            tep_db_query("INSERT INTO " . TABLE_SUBSCRIPTIONS . " (productid, pay_period_type, price_period, oneday_price, days_as_period, pay_dates) VALUES ( '$products_id', '" . $sql_data_array1['pay_period_type'] . "', '" . $sql_data_array1['price_period'] . "', '" . $sql_data_array1['oneday_price'] . "','" . $sql_data_array1['days_as_period'] . "', NULL)");

            tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$current_category_id . "')");
          } elseif ($action == 'update_product') {
            //$update_sql_data = array('products_last_modified' => 'now()');
             $update_sql_data = array('products_last_modified' => 'now()', 'cost_price' => '1');

            $sql_data_array = array_merge($sql_data_array, $update_sql_data);
            
            $issubsquer = tep_db_query("Select count(*) as total from ".TABLE_SUBSCRIPTIONS." where productid = '". $products_id ." '");
            $issubs_check = tep_db_fetch_array($issubsquer);
            if ($issubs_check['total'] > 0) {
            tep_db_perform(TABLE_SUBSCRIPTIONS, $sql_data_array1, 'update', 'productid = \'' . tep_db_input($products_id) . '\'');}
            else
            {
$sud_data_array = array_merge($products_id, $sql_data_array1);
            tep_db_query("INSERT INTO " . TABLE_SUBSCRIPTIONS . " (productid, pay_period_type, price_period, oneday_price, days_as_period, pay_dates) VALUES ( '$products_id', '" . $sql_data_array1['pay_period_type'] . "', '" . $sql_data_array1['price_period'] . "', '" . $sql_data_array1['oneday_price'] . "','" . $sql_data_array1['days_as_period'] . "', NULL)");
            }
            tep_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
          }
          
          /** AJAX Attribute Manager  **/ 
  require_once('attributeManager/includes/attributeManagerUpdateAtomic.inc.php'); 
/** AJAX Attribute Manager  end **/


     
  
  // BOF Separate Pricing Per Customer, Price Break 1.11.3 mod
 $customers_group_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " where customers_group_id != '0' order by customers_group_id");
while ($customers_group = tep_db_fetch_array($customers_group_query)) // Gets all of the customers groups
  {
  $attributes_query = tep_db_query("select customers_group_id, customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where ((products_id = '" . $products_id . "') && (customers_group_id = " . $customers_group['customers_group_id'] . ")) order by customers_group_id");
  $attributes = tep_db_fetch_array($attributes_query);
  if (tep_db_num_rows($attributes_query) > 0) {
    if ($_POST['sppcoption'][$customers_group['customers_group_id']]) { // this is checking if the check box is checked
      if ($attributes['customers_group_id'] == $customers_group['customers_group_id'] ) {
	      $sppc_update_query = "set ";
	if (isset($_POST['sppcprice'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= "customers_group_price = '" . $_POST['sppcprice'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_qty_blocks'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_qty_blocks = '" . $_POST['sppcproducts_qty_blocks'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price1'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price1 = '" . $_POST['sppcproducts_price1'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price1_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price1_qty = '" . $_POST['sppcproducts_price1_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price2'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price2 = '" . $_POST['sppcproducts_price2'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price2_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price2_qty = '" . $_POST['sppcproducts_price2_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price3'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price3 = '" . $_POST['sppcproducts_price3'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price3_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price3_qty = '" . $_POST['sppcproducts_price3_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price4'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price4 = '" . $_POST['sppcproducts_price4'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price4_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price4_qty = '" . $_POST['sppcproducts_price4_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price5'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price5 = '" . $_POST['sppcproducts_price5'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price5_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price5_qty = '" . $_POST['sppcproducts_price5_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price6'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price6 = '" . $_POST['sppcproducts_price6'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price6_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price6_qty = '" . $_POST['sppcproducts_price6_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price7'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price7 = '" . $_POST['sppcproducts_price7'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price7_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price7_qty = '" . $_POST['sppcproducts_price7_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price8'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price8 = '" . $_POST['sppcproducts_price8'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price8_qty'][$customers_group['customers_group_id']])) {
	   $sppc_update_query .= " products_price8_qty = '" . $_POST['sppcproducts_price8_qty'][$customers_group['customers_group_id']] . "' ";
	} // now we need to get rid of the last comma in the query string...
	   $sppc_update_query = rtrim($sppc_update_query);
	   $query_string_length = strlen($sppc_update_query);
	 if (substr($sppc_update_query, -1) == ",") {
		$sppc_update_query = substr($sppc_update_query, $query_string_length-1);
	 } 

	    tep_db_query("update " . TABLE_PRODUCTS_GROUPS . " " . $sppc_update_query . " where customers_group_id = '" . $attributes['customers_group_id'] . "' and products_id = '" . $products_id . "'");
     //   $attributes = tep_db_fetch_array($attributes_query);
      } 
  
    }  else { // checkbox is unchecked
      tep_db_query("delete from " . TABLE_PRODUCTS_GROUPS . " where customers_group_id = '" . $customers_group['customers_group_id'] . "' and products_id = '" . $products_id . "'");
      $attributes = tep_db_fetch_array($attributes_query);
    }
// next } : end if (tep_db_num_rows($attributes_query) > 0)
  } 
  elseif (($_POST['sppcoption'][$customers_group['customers_group_id']]) && ($_POST['sppcprice'][$customers_group['customers_group_id']] != '')) {
	      $sppc_insert_query = "set products_id = '" . $products_id . "', customers_group_id= '" . $customers_group['customers_group_id'] . "', ";
	if (isset($_POST['sppcprice'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= "customers_group_price = '" . $_POST['sppcprice'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_qty_blocks'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_qty_blocks = '" . $_POST['sppcproducts_qty_blocks'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price1'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price1 = '" . $_POST['sppcproducts_price1'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price1_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price1_qty = '" . $_POST['sppcproducts_price1_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price2'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price2 = '" . $_POST['sppcproducts_price2'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price2_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price2_qty = '" . $_POST['sppcproducts_price2_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price3'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price3 = '" . $_POST['sppcproducts_price3'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price3_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price3_qty = '" . $_POST['sppcproducts_price3_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price4'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price4 = '" . $_POST['sppcproducts_price4'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price4_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price4_qty = '" . $_POST['sppcproducts_price4_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price5'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price5 = '" . $_POST['sppcproducts_price5'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price5_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price5_qty = '" . $_POST['sppcproducts_price5_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price6'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price6 = '" . $_POST['sppcproducts_price6'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price6_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price6_qty = '" . $_POST['sppcproducts_price6_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price7'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price7 = '" . $_POST['sppcproducts_price7'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price7_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price7_qty = '" . $_POST['sppcproducts_price7_qty'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price8'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price8 = '" . $_POST['sppcproducts_price8'][$customers_group['customers_group_id']] . "', ";
	} if (isset($_POST['sppcproducts_price8_qty'][$customers_group['customers_group_id']])) {
	   $sppc_insert_query .= " products_price8_qty = '" . $_POST['sppcproducts_price8_qty'][$customers_group['customers_group_id']] . "' ";
	} // now we need to get rid of the last comma in the query string...
	   $sppc_insert_query = rtrim($sppc_insert_query);
	   $query_string_length = strlen($sppc_insert_query);
	 if (substr($sppc_insert_query, -1) == ",") {
		$sppc_insert_query = substr($sppc_insert_query, $query_string_length-1);
	 } 

    tep_db_query("insert into " . TABLE_PRODUCTS_GROUPS . " " . $sppc_insert_query . "");
//    $attributes = tep_db_fetch_array($attributes_query);
  } // end elseif
} // end while ($customers_group = tep_db_fetch_array($customers_group_query))
  // EOF Separate Pricing Per Customer, Price Break 1.11.3 mod
  

          $languages = tep_get_languages();
          for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
            $language_id = $languages[$i]['id'];

            $sql_data_array = array('products_name' => tep_db_prepare_input($_POST['products_name'][$language_id]),
                                    'products_description' => tep_db_prepare_input($_POST['products_description'][$language_id]),
                                    'products_url' => tep_db_prepare_input($_POST['products_url'][$language_id]));

            if ($action == 'insert_product') {
              $insert_sql_data = array('products_id' => $products_id,
                                       'language_id' => $language_id);

              $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

              tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
              
              
              $extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE products_id = " . (int)$products_id);
          while ($products_extra_fields = tep_db_fetch_array($extra_fields_query)) {
            $extra_product_entry[$products_extra_fields['products_extra_fields_id']] = $products_extra_fields['products_extra_fields_value'];
          }

          if ($_POST['extra_field']) { // Check to see if there are any need to update extra fields.
            foreach ($_POST['extra_field'] as $key=>$val) {
            
              if (isset($extra_product_entry[$key])) { // an entry exists
                if ($val == '') tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " where products_id = " . (int)$products_id . " AND  products_extra_fields_id = " . $key);
                else tep_db_query("UPDATE " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " SET products_extra_fields_value = '" . tep_db_prepare_input($val) . "' WHERE products_id = " . (int)$products_id . " AND  products_extra_fields_id = " . $key);
              }
              else { // an entry does not exist
                if ($val != '') tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " (products_id, products_extra_fields_id, products_extra_fields_value) VALUES ('" . (int)$products_id . "', '" . $key . "', '" . tep_db_prepare_input($val) . "')");
              }
            }
          }
              
            } elseif ($action == 'update_product') {
              tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
              
                  // START: Extra Fields Contribution
          $extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE products_id = " . (int)$products_id);
          while ($products_extra_fields = tep_db_fetch_array($extra_fields_query)) {
            $extra_product_entry[$products_extra_fields['products_extra_fields_id']] = $products_extra_fields['products_extra_fields_value'];
          }

          if ($_POST['extra_field']) { // Check to see if there are any need to update extra fields.
            foreach ($_POST['extra_field'] as $key=>$val) {
            
              if (isset($extra_product_entry[$key])) { // an entry exists
                if ($val == '') tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " where products_id = " . (int)$products_id . " AND  products_extra_fields_id = " . $key);
                else tep_db_query("UPDATE " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " SET products_extra_fields_value = '" . tep_db_prepare_input($val) . "' WHERE products_id = " . (int)$products_id . " AND  products_extra_fields_id = " . $key);
              }
              else { // an entry does not exist
                if ($val != '') tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " (products_id, products_extra_fields_id, products_extra_fields_value) VALUES ('" . (int)$products_id . "', '" . $key . "', '" . tep_db_prepare_input($val) . "')");
              }
            }
          } // Check to see if there are any need to update extra fields.
          // END: Extra Fields Contribution

            }
          }

          if (USE_CACHE == 'true') {
            tep_reset_cache_block('categories');
            tep_reset_cache_block('also_purchased');
          }

          tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id));
        }
        break;
      case 'copy_to_confirm':
        if (isset($_POST['products_id']) && isset($_POST['categories_id'])) {
          $products_id = tep_db_prepare_input($_POST['products_id']);
          $categories_id = tep_db_prepare_input($_POST['categories_id']);

          if ($_POST['copy_as'] == 'link') {
            if ($categories_id != $current_category_id) {
              $check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$products_id . "' and categories_id = '" . (int)$categories_id . "'");
              $check = tep_db_fetch_array($check_query);
              if ($check['total'] < '1') {
                tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$categories_id . "')");
              }
            } else {
              $messageStack->add_session(ERROR_CANNOT_LINK_TO_SAME_CATEGORY, 'error');
            }
          } elseif ($_POST['copy_as'] == 'duplicate') {
          
          
            $product_query = tep_db_query("select products_quantity, products_model, Featured_Product, products_image, products_price, products_price1, products_price2, products_price3, products_price4, products_price5, products_price6, products_price7, products_price8, products_price1_qty, products_price2_qty, products_price3_qty, products_price4_qty, products_price5_qty, products_price6_qty, products_price7_qty, products_price8_qty, products_qty_blocks, products_date_added, products_last_modified, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, customer_id, products_ordered, products_length, products_width, products_depth, vendors_id, vendors_product_price, vendors_prod_id, vendors_prod_comments, products_hide_from_groups, supplier_id, suppliers_id, cost_price, products_price_myself, affiliate_allow_product, products_pdfupload, products_fileupload, products_vidupload, products_mp3  from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
            $product = tep_db_fetch_array($product_query);

            tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model, Featured_Product, products_image, products_pdfupload, products_fileupload, products_vidupload, products_mp3, products_price, products_date_added, products_last_modified, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, customer_id, products_ordered, products_length, products_width, products_depth, vendors_id, vendors_product_price, vendors_prod_id, vendors_prod_comments, products_hide_from_groups, supplier_id, suppliers_id, cost_price, products_price_myself, affiliate_allow_product, products_price1, products_price2, products_price3, products_price4, products_price5, products_price6, products_price7, products_price8, products_price1_qty, products_price2_qty, products_price3_qty, products_price4_qty, products_price5_qty, products_price6_qty, products_price7_qty, products_price8_qty, products_qty_blocks) values ('" . $product['products_quantity'] . "', 
            '" . $product['products_model'] . "', 
            '" . $product['Featured_Product'] . "', 
            '" . $product['products_image'] . "', 
            '" . $product['products_pdfupload'] . "', 
            '" . $product['products_fileupload'] . "',
            '" . $product['products_vidupload'] . "', 
            '" . $product['products_mp3'] . "',
            '" . $product['products_price'] . "', 
            '" . $product['products_date_added'] . "', 
            '" . $product['products_last_modified'] . "', 
            '" . $product['products_date_available'] . "', 
            '" . $product['products_weight'] . "', 
            '" . $product['products_status'] . "', 
            '" . $product['products_tax_class_id'] . "', 
            '" . $product['manufacturers_id'] . "', 
            '" . $product['customer_id'] . "', 
            '" . $product['products_ordered'] . "', 
            '" . $product['products_length'] . "', 
            '" . $product['products_width'] . "', 
            '" . $product['products_depth'] . "', 
            '" . $product['vendors_id'] . "', 
            '" . $product['vendors_product_price'] . "', 
            '" . $product['vendors_prod_id'] . "', 
            '" . $product['vendors_prod_comments'] . "', 
            '" . $product['products_hide_from_groups'] . "', 
            '" . $product['supplier_id'] . "', 
            '" . $product['suppliers_id'] . "', 
            '" . $product['cost_price'] . "', 
            '" . $product['products_price_myself'] . "', 
            '" . $product['affiliate_allow_product'] . "',
            '" . tep_db_input($product['products_price1']) . "',
            '" . tep_db_input($product['products_price2']) . "', 
            '" . tep_db_input($product['products_price3']) . "', 
            '" . tep_db_input($product['products_price4']) . "', 
            '" . tep_db_input($product['products_price5']) . "', 
            '" . tep_db_input($product['products_price6']) . "', 
            '" . tep_db_input($product['products_price7']) . "', 
            '" . tep_db_input($product['products_price8']) .  "', 
            '" . tep_db_input($product['products_price1_qty']) . "', 
            '" . tep_db_input($product['products_price2_qty']) . "', 
            '" . tep_db_input($product['products_price3_qty']) . "', 
            '" . tep_db_input($product['products_price4_qty']) . "', 
            '" . tep_db_input($product['products_price5_qty']) . "', 
            '" . tep_db_input($product['products_price6_qty']) . "', 
            '" . tep_db_input($product['products_price7_qty']) . "', 
            '" . tep_db_input($product['products_price8_qty']) ."', 
            '" . tep_db_input($product['products_qty_blocks']) . "')");
            $dup_products_id = tep_db_insert_id();
            
            $sub_query = tep_db_query("select  price_period, oneday_price, days_as_period, pay_period_type  from " . TABLE_SUBSCRIPTIONS . " where productid = '" . tep_db_input($products_id) . "'");
            $sub = tep_db_fetch_array($sub_query);
            tep_db_query("INSERT INTO " . TABLE_SUBSCRIPTIONS . " (productid, pay_period_type, price_period, oneday_price, days_as_period, pay_dates) VALUES ( '$products_id', '" . $sub['pay_period_type'] . "', '" . $sub['price_period'] . "', '" . $sub['oneday_price'] . "', '" . $sub['days_as_period'] . "', NULL)");

            $description_query = tep_db_query("select language_id, products_name, products_description, products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$products_id . "'");
            while ($description = tep_db_fetch_array($description_query)) {
              tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . (int)$dup_products_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['products_name']) . "', '" . tep_db_input($description['products_description']) . "', '" . tep_db_input($description['products_url']) . "', '0')");
            }

            tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$dup_products_id . "', '" . (int)$categories_id . "')");
            // BOF Separate Pricing Per Customer 26042006 by Infobroker

 $customers_group_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " where customers_group_id != '0' order by customers_group_id");
while ($customers_group = tep_db_fetch_array($customers_group_query)) // Gets all of the customers groups
  {
    $attributes_query = tep_db_query("select customers_group_id, customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where ((products_id = '" . $products_id . "') && (customers_group_id = " . $customers_group['customers_group_id'] . ")) order by customers_group_id");
  $attributes = tep_db_fetch_array($attributes_query);
  
            tep_db_query("insert into " . TABLE_PRODUCTS_GROUPS . " (customers_group_id, customers_group_price, products_id) values ('" . $attributes['customers_group_id'] . "', '" . tep_db_input($attributes['customers_group_price']) . "', '" . (int)$dup_products_id . "')");



}
  // EOF Separate Pricing Per Customer  26042006 by Infobroker
            $products_id = $dup_products_id;
          }

          if (USE_CACHE == 'true') {
            tep_reset_cache_block('categories');
            tep_reset_cache_block('also_purchased');
          }
        }

        tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $categories_id . '&pID=' . $products_id));
        break;
      case 'new_product_preview':
// copy image only if modified
        $products_image = new upload('products_image');
        $products_image->set_destination(DIR_FS_CATALOG_IMAGES);
        if ($products_image->parse() && $products_image->save()) {
          $products_image_name = $products_image->filename;
          AddWatermark($products_image->filename);
        } else {
          $products_image_name = (isset($_POST['products_previous_image']) ? $_POST['products_previous_image'] : '');
        }
        
        $products_pdfupload = new upload('products_pdfupload');
        $products_pdfupload->set_destination(DIR_FS_CATALOG_IMAGES);
        
        if ($products_pdfupload->parse() && $products_pdfupload->save()) {
          $products_pdfupload_name = $products_pdfupload->filename;
        } else {
          $products_pdfupload_name = (isset($_POST['products_previous_pdfupload']) ? $_POST['products_previous_pdfupload'] : '');
        }
        
        $products_fileupload = new upload('products_fileupload');
        $products_fileupload->set_destination(DIR_FS_CATALOG_IMAGES);
        
        if ($products_fileupload->parse() && $products_fileupload->save()) {
          $products_fileupload_name = $products_fileupload->filename;
        } else {
          $products_fileupload_name = (isset($_POST['products_previous_fileupload']) ? $_POST['products_previous_fileupload'] : '');
        }
        
        $products_mp3= new upload('products_mp3');
        $products_mp3->set_destination(DIR_FS_CATALOG_IMAGES);
        
        if ($products_mp3->parse() && $products_mp3->save()) {
          $products_mp3_name = $products_mp3->filename;
        } else {
          $products_mp3_name = (isset($_POST['products_previous_mp3']) ? $_POST['products_previous_mp3'] : '');
        }
        
        $products_vidupload = new upload('products_vidupload');
        $products_vidupload->set_destination(DIR_FS_CATALOG_IMAGES);
        
        if ($products_vidupload->parse() && $products_vidupload->save()) {
          $products_vidupload_name = $products_vidupload->filename;
        } else {
          $products_vidupload_name = (isset($_POST['products_previous_vidupload']) ? $_POST['products_previous_vidupload'] : '');
        }
        break;
    }
  }

// check if the catalog image directory exists
  if (is_dir(DIR_FS_CATALOG_IMAGES)) {
    if (!is_writeable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
  } else {
    $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
  }
?>

<link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_COMPONENT ?>includes/stylesheet.css">
<script language="javascript" src="<?php echo DIR_WS_COMPONENT ?>includes/general.js"></script>
<!-- AJAX Attribute Manager  -->
<?php require_once( DIR_WS_COMPONENT . 'attributeManager/includes/attributeManagerHeader.inc.php' )?>
<!-- AJAX Attribute Manager  end -->



<div id="spiffycalendar" class="text"></div>

<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<script>
//window.onload="goOnLoad();"
</script>
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2" class="adminlist"> 
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top">
<?php
  if ($action == 'new_product') {
    $parameters = array('products_name' 		=> '',
                       'products_description' 	=> '',
                       'products_url' 			=> '',
                       'products_id' 			=> '',
                       'products_quantity' 		=> '',
                       'products_model' 		=> '',
                       'Featured_Product' 		=> '',
                       'products_image' 		=> '',
                       'products_price' 		=> '',
                       'products_weight'		=> '',
                       'products_date_added' 	=> '',
                       'products_last_modified' => '',
                       'products_date_available'=> '',
                       'products_status' 		=> '',
                       'products_tax_class_id' 	=> '',
                       'vendors_product_price' 	=> '',
                       'vendors_prod_comments' 	=> '',
                       'vendors_prod_id' 		=> '',
                       'vendors_id' 			=> '',
                       'products_hide_from_groups' => '',
                       'manufacturers_id' 		=> '',
                       'suppliers_id' => '',
                       'products_price1' => '',
                       'products_price2' => '',
                       'products_price3' => '',
                       'products_price4' => '',
                       'products_price5' => '',
                       'products_price6' => '',
                       'products_price7' => '',
                       'products_price8' => '',
                       'products_price1_qty' => '',
                       'products_price2_qty' => '',
                       'products_price3_qty' => '',
                       'products_price4_qty' => '',
                       'products_price5_qty' => '',
                       'products_price6_qty' => '',
                       'products_price7_qty' => '',
                       'products_price8_qty' => '',
                       'products_qty_blocks' => '',
                       'affiliate_allow_product' => '');

    $pInfo = new objectInfo($parameters);

    if (isset($_GET['pID']) && empty($_POST)) {
    
    // START: Extra Fields Contribution	  
      $products_extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE products_id=" . (int)$_GET['pID']);
      while ($products_extra_fields = tep_db_fetch_array($products_extra_fields_query)) {
        $extra_field[$products_extra_fields['products_extra_fields_id']] = $products_extra_fields['products_extra_fields_value'];
      }
	  $extra_field_array=array('extra_field'=>$extra_field);
	  $pInfo->objectInfo($extra_field_array);
// END: Extra Fields Contribution

 

$product_query = tep_db_query("select s.price_period, s.oneday_price, s.days_as_period, s.pay_period_type, pd.products_name, pd.products_description, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.Featured_Product, p.products_image, p.products_price, p.vendors_product_price, p.products_weight, p.products_hide_from_groups, p.vendors_prod_comments, p.products_date_added, p.vendors_prod_id, p.affiliate_allow_product, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.vendors_id, p.products_hide_from_groups, p.manufacturers_id,p.products_length, p.products_width, p.products_depth, p.suppliers_id, p.products_price1, p.products_price2, p.products_price3, p.products_price4, p.products_price5, p.products_price6, p.products_price7, p.products_price8, p.products_price1_qty, p.products_price2_qty, p.products_price3_qty, p.products_price4_qty, p.products_price5_qty, p.products_price6_qty, p.products_price7_qty, p.products_price8_qty, p.products_qty_blocks, p.products_pdfupload, p.products_fileupload, p.products_vidupload, p.products_mp3  from " . TABLE_PRODUCTS . " p, " . TABLE_SUBSCRIPTIONS ." s, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . $_REQUEST['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and s.productid = '" . $_REQUEST['pID'] . "'");
      
      if (tep_db_num_rows($product_query) < 1) {
  $conv_query = tep_db_query("select products_id from " . TABLE_PRODUCTS . " order by products_id ");
   while ($conv_query_insert =  tep_db_fetch_array($conv_query)) {
    $conv_isthere = tep_db_query("select productid from `". TABLE_SUBSCRIPTIONS . "` where productid = '". $conv_query_insert['products_id'] . "'");
    
    if (tep_db_num_rows($conv_isthere) < 1) {
    
      tep_db_query("INSERT IGNORE INTO `". TABLE_SUBSCRIPTIONS . "` values ('" . $conv_query_insert['products_id'] . "','Annually','0.0000','0.000','0','')");
      }
   
  }
  //index3.php?cPath=5_6&pID=10&action=new_product&option=com_oscommerce&osMod=categories
  tep_redirect("index3.php?cPath={$_GET['cPath']}&action=new_product&option=com_oscommerce&osMod=categories&pID={$_GET['pID']}");
  }
      
      
      $product = tep_db_fetch_array($product_query);
     


      $pInfo->objectInfo($product);
      
      
    } elseif (tep_not_null($_POST)) {
      $pInfo->objectInfo($_POST);
      $products_name = $_POST['products_name'];
      $products_description = $_POST['products_description'];
      $products_url = $_POST['products_url'];
      
       $price_period = $_POST['price_period'];
      $oneday_price = $_POST['oneday_price'];
      $days_as_period = $_POST['days_as_period'];
      $pay_period_type = $_POST['pay_period_type'];
    } else {
      $pInfo = new objectInfo(array());
    }

    $manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE));
    $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
    while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
      $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
                                     'text' => $manufacturers['manufacturers_name']);
    }
    //MVS start
    $vendors_array = array(array('id' => '1', 'text' => 'NONE'));
    $vendors_query = tep_db_query("select vendors_id, vendors_name from " . 

TABLE_VENDORS . " order by vendors_name");
    while ($vendors = tep_db_fetch_array($vendors_query)) {
      $vendors_array[] = array('id' => $vendors['vendors_id'],
                                     'text' => $vendors['vendors_name']);
    }
    //MVS end

    $tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
    $tax_class_query = tep_db_query("select tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
    while ($tax_class = tep_db_fetch_array($tax_class_query)) {
      $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
                                 'text' => $tax_class['tax_class_title']);
    }
    
     $supplier_array = array(array('id' => 0, 'text' => TEXT_NONE));
$supplier_query = tep_db_query("select suppliers_id, suppliers_name from " . TABLE_SUPPLIERS . " order by suppliers_name");

            while ( $supplier_result = tep_db_fetch_array($supplier_query) ){

                        $supplier_array[] = array('id' => $supplier_result['suppliers_id'],
                                                'text' => $supplier_result['suppliers_name']);

            }

    $languages = tep_get_languages();

    if (!isset($pInfo->products_status)) $pInfo->products_status = '1';
    switch ($pInfo->products_status) {
      case '0': $in_status = false; $out_status = true; break;
      case '1':
      default: $in_status = true; $out_status = false;
    }
    
    if (!isset($pInfo->affiliate_allow_product)) $pInfo->affiliate_allow_product = '1';
    switch ($pInfo->affiliate_allow_product) {
      case '0': $in_status2 = false; $out_status2 = true; break;
      case '1':
      default: $in_status2 = true; $out_status2 = false;
    }
?>
<link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_COMPONENT ?>includes/javascript/spiffyCal/spiffyCal_v2_1.css">
<script language="JavaScript" src="<?php echo DIR_WS_COMPONENT ?>includes/javascript/spiffyCal/spiffyCal_v2_1.js"></script>
<script language="javascript"><!--
  var dateAvailable = new ctlSpiffyCalendarBox("dateAvailable", "new_product", "products_date_available","btnDate1","<?php echo $pInfo->products_date_available; ?>",scBTNMODE_CUSTOMBLUE);
//--></script>
<script language="javascript"><!--
var tax_rates = new Array();
<?php
    for ($i=0, $n=sizeof($tax_class_array); $i<$n; $i++) {
      if ($tax_class_array[$i]['id'] > 0) {
        echo 'tax_rates["' . $tax_class_array[$i]['id'] . '"] = ' . tep_get_tax_rate_value($tax_class_array[$i]['id']) . ';' . "\n";
      }
    }
?>

function doRound(x, places) {
  return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
}

function getTaxRate() {
  var selected_value = document.forms["new_product"].products_tax_class_id.selectedIndex;
  var parameterVal = document.forms["new_product"].products_tax_class_id[selected_value].value;

  if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
    return tax_rates[parameterVal];
  } else {
    return 0;
  }
}

function updateGross() {
  var taxRate = getTaxRate();
  var grossValue = document.forms["new_product"].products_price.value;

  if (taxRate > 0) {
    grossValue = grossValue * ((taxRate / 100) + 1);
  }

  document.forms["new_product"].products_price_gross.value = doRound(grossValue, 4);
}

function updateNet() {
  var taxRate = getTaxRate();
  var netValue = document.forms["new_product"].products_price_gross.value;

  if (taxRate > 0) {
    netValue = netValue / ((taxRate / 100) + 1);
  }

  document.forms["new_product"].products_price.value = doRound(netValue, 4);
}
//--></script>
    <?php echo tep_draw_form('new_product', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . (isset($_REQUEST['pID']) ? '&pID=' . $_REQUEST['pID'] : '') . '&action=new_product_preview'), 'post', 'enctype="multipart/form-data"'); ?>



    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo sprintf(TEXT_NEW_PRODUCT, tep_output_generated_category_path($current_category_id)); ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_STATUS; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('products_status', '1', $in_status) . '&nbsp;' . TEXT_PRODUCT_AVAILABLE . '&nbsp;' . tep_draw_radio_field('products_status', '0', $out_status) . '&nbsp;' . TEXT_PRODUCT_NOT_AVAILABLE; ?></td>
          </tr>
            <tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_AFFILIATE; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('affiliate_allow_product', '1', $in_status2) . '&nbsp;' . TEXT_PRODUCT_AFFILIATE . '&nbsp;' . tep_draw_radio_field('affiliate_allow_product', '0', $out_status2) . '&nbsp;' . TEXT_PRODUCT_NOT_AFFILIATE; ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          
          
          
          <tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_DATE_AVAILABLE; ?><br><small>(YYYY-MM-DD)</small></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;'; ?><script language="javascript">dateAvailable.writeControl(); dateAvailable.dateFormat="yyyy-MM-dd";</script></td>
          </tr>
          <?php //MVS start
           ?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','1', '10'); ?></td>
          </tr>
          <tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_VENDORS; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_pull_down_menu('vendors_id', $vendors_array, $pInfo->vendors_id); ?></td>
          </tr>
          <?php //MVS end
           ?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_MANUFACTURER; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_pull_down_menu('manufacturers_id', $manufacturers_array, $pInfo->manufacturers_id); ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          

                                    <tr>

                                                <td class="maincol"><?php echo TEXT_SUPPLIER; ?></td>

                                                <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_pull_down_menu('products_suppliers_id', $supplier_array, $pInfo->suppliers_id);?></td>

                                    </tr>

                                   

                        <tr>

            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>

 
<?php
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
?>
          <tr>
            <td class="maincol"><?php if ($i == 0) echo TEXT_PRODUCTS_NAME; ?></td>
            <td class="maincol"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('products_name[' . $languages[$i]['id'] . ']', (isset($products_name[$languages[$i]['id']]) ? stripslashes($products_name[$languages[$i]['id']]) : tep_get_products_name($pInfo->products_id, $languages[$i]['id']))); ?></td>
          </tr>
<?php
    }
?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr bgcolor="#ebebff">
            <td class="maincol"><?php echo TEXT_PRODUCTS_TAX_CLASS; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_pull_down_menu('products_tax_class_id', $tax_class_array, $pInfo->products_tax_class_id, 'onchange="updateGross()"'); ?></td>
          </tr>
          <tr bgcolor="#ebebff">
            <td class="maincol"><?php echo TEXT_PRODUCTS_PRICE_NET; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price', $pInfo->products_price, 'onKeyUp="updateGross()"'); ?></td>
          </tr>
          <tr bgcolor="#ebebff">
            <td class="maincol"><?php echo TEXT_PRODUCTS_PRICE_GROSS; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price_gross', $pInfo->products_price, 'OnKeyUp="updateNet()"'); ?></td>
          </tr>
          <?php //MVS start
           ?>
          <tr bgcolor="#ebebff">
          <td class="maincol"><?php echo TEXT_VENDORS_PRODUCT_PRICE_BASE; 

?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('vendors_product_price', $pInfo->vendors_product_price, 'onKeyUp="updateNet()"'); ?></td>
          </tr>
          <?php  //MVS end
          ?>




          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
<script language="javascript"><!--
updateGross();
//--></script>
<?php $name_retail_query = tep_db_query("select customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " where customers_group_id = '0'");
$name_retail = tep_db_fetch_array($name_retail_query);
?>
<tr bgcolor="#ebebff">
<td colspan="2" width="100%">
<div class="hide_templatemod"><strong><?php echo TEXT_PRICE_BREAK;?> - <?php echo $name_retail['customers_group_name'] ?> - <?php echo TEXT_EXPAND;?></strong>
</div>
<div class="show_templatemod" width="100%">
	<div>
	<table width="100%">
         <!-- <tr bgcolor="#ebebff">
            <td class="main" colspan="2"><strong><?php echo $name_retail['customers_group_name'] ?>:</strong></td>
          </tr>-->
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_QTY_BLOCKS; ?></td>
            <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_qty_blocks', $pInfo->products_qty_blocks, 'size="10"') . '&nbsp;' . TEXT_PRODUCTS_QTY_BLOCKS_INFO ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE1; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price1', $pInfo->products_price1, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE1_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price1_qty', $pInfo->products_price1_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE2; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price2', $pInfo->products_price2, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE2_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price2_qty', $pInfo->products_price2_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE3; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price3', $pInfo->products_price3, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE3_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price3_qty', $pInfo->products_price3_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE4; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price4', $pInfo->products_price4, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE4_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price4_qty', $pInfo->products_price4_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE5; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price5', $pInfo->products_price5, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE5_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price5_qty', $pInfo->products_price5_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE6; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price6', $pInfo->products_price6, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE6_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price6_qty', $pInfo->products_price6_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE7; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price7', $pInfo->products_price7, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE7_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price7_qty', $pInfo->products_price7_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE8; ?></td>
            <td colspan="3" align="left"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price8', $pInfo->products_price8, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE8_QTY; ?></td>
            <td class="main" align="left"><?php echo tep_draw_input_field('products_price8_qty', $pInfo->products_price8_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
     </table>
           </div></div>
     </td></tr>
    
     
<!-- EOF Price Break 1.11.3 Retail -->
<!-- BOF Separate Pricing Per Customer -->
<?php
    $customers_group_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " where customers_group_id != '0' order by customers_group_id");
    $header = false;
    while ($customers_group = tep_db_fetch_array($customers_group_query)) {
	    
     if (tep_db_num_rows($customers_group_query) > 0) {
       $attributes_query = tep_db_query("select customers_group_id, customers_group_price, products_price1, products_price2, products_price3, products_price4, products_price5, products_price6, products_price7, products_price8, products_price1_qty, products_price2_qty, products_price3_qty, products_price4_qty, products_price5_qty, products_price6_qty, products_price7_qty, products_price8_qty, products_qty_blocks from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . $pInfo->products_id . "' and customers_group_id = '" . $customers_group['customers_group_id'] . "' order by customers_group_id");
     } else {
         $attributes = array('customers_group_id' => 'new');
     }
 if (!$header) { ?>

    <tr bgcolor="#ebebff"">
    <td class="main" colspan="2" style="font-style: italic">Note that if the price field for the customer group is left empty, <b>no</b> price and <b>no</b> price break levels and quantities for that customer group will be inserted in the database.<br />
If a field or fields is/are filled, but the checkbox is unchecked no price/price break levels etc. will be inserted either.<br />
If a price and price break levels are already inserted in the database, but the checkbox unchecked they will be removed from the database.
</td>
    </tr>
 <?php 
 $header = true; 
 } // end if (!header), makes sure this is only shown once   
 ?><tr><td colspan="2">
 <div class="hide_templatemod"><strong><?php echo TEXT_PRICE_BREAK;?> - <?php echo $customers_group['customers_group_name'] ?> - <?php echo TEXT_EXPAND;?></strong>
</div>
<div class="show_templatemod" width="100%">
<div>
<table>
        <tr bgcolor="#ebebff">
       <td class="main"><?php 
             if (isset($pInfo->sppcoption)) {
	   echo tep_draw_checkbox_field('sppcoption[' . $customers_group['customers_group_id'] . ']', 'sppcoption[' . $customers_group['customers_group_id'] . ']', (isset($pInfo->sppcoption[ $customers_group['customers_group_id']])) ? 1: 0);
      } else {
      echo tep_draw_checkbox_field('sppcoption[' . $customers_group['customers_group_id'] . ']', 'sppcoption[' . $customers_group['customers_group_id'] . ']', true) . '&nbsp;' . $customers_group['customers_group_name'];
      }
      ?>
 &nbsp;</td>
       <td class="main"><?php
       $customer_prices_set = false;
       $customer_prices_in_post = false;
       if ($attributes = tep_db_fetch_array($attributes_query)) { 
	       $customer_prices_set = true;
       echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcprice[' . $customers_group['customers_group_id'] . ']', $attributes['customers_group_price']); 
       }  else {
	       if (isset($pInfo->sppcprice[$customers_group['customers_group_id']])) { // when a preview was done and the back button used
		       $customer_prices_in_post = true;
		       $sppc_cg_price = $pInfo->sppcprice[$customers_group['customers_group_id']];
	       } else { // nothing in the db, nothing in the post variables
		       $sppc_cg_price = '';
	       }
	   echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcprice[' . $customers_group['customers_group_id'] . ']', $sppc_cg_price );
	 }  ?></td>
    </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_QTY_BLOCKS; ?></td>
            <td class="main"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_qty_blocks = $attributes['products_qty_blocks'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_qty_blocks = $pInfo->sppcproducts_qty_blocks[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_qty_blocks = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_qty_blocks[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_qty_blocks, 'size="10"') . '&nbsp;' . TEXT_PRODUCTS_QTY_BLOCKS_INFO;
 ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE1; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price1 = $attributes['products_price1'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price1 = $pInfo->sppcproducts_price1[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price1 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price1[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price1, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE1_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price1_qty = $attributes['products_price1_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price1_qty = $pInfo->sppcproducts_price1_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price1_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price1_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price1_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE2; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price2 = $attributes['products_price2'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price2 = $pInfo->sppcproducts_price2[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price2 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price2[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price2, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE2_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price2_qty = $attributes['products_price2_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price2_qty = $pInfo->sppcproducts_price2_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price2_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price2_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price2_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE3; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price3 = $attributes['products_price3'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price3 = $pInfo->sppcproducts_price3[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price3 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price3[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price3, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE3_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price3_qty = $attributes['products_price3_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price3_qty = $pInfo->sppcproducts_price3_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price3_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price3_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price3_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE4; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price4 = $attributes['products_price4'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price4 = $pInfo->sppcproducts_price4[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price4 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price4[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price4, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE4_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price4_qty = $attributes['products_price4_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price4_qty = $pInfo->sppcproducts_price4_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price4_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price4_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price4_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE5; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price5 = $attributes['products_price5'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price5 = $pInfo->sppcproducts_price5[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price5 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price5[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price5, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE5_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price5_qty = $attributes['products_price5_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price5_qty = $pInfo->sppcproducts_price5_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price5_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price5_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price5_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE6; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price6 = $attributes['products_price6'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price6 = $pInfo->sppcproducts_price6[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price6 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price6[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price6, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE6_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price6_qty = $attributes['products_price6_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price6_qty = $pInfo->sppcproducts_price6_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price6_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price6_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price6_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE7; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price7 = $attributes['products_price7'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price7 = $pInfo->sppcproducts_price7[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price7 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price7[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price7, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE7_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price7_qty = $attributes['products_price7_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price7_qty = $pInfo->sppcproducts_price7_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price7_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price7_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price7_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_PRICE8; ?></td>
            <td class="main"><table border="0" cellspacing="0" cellpadding="0" width="80%"><tr>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price8 = $attributes['products_price8'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price8 = $pInfo->sppcproducts_price8[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price8 = ''; 
	    } 
	    echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sppcproducts_price8[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price8, 'size="10"'); ?></td>
            <td class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE8_QTY; ?></td>
            <td class="main" align="left"><?php if ($customer_prices_set == true) {
	    $sppc_cg_products_price8_qty = $attributes['products_price8_qty'] ;
	    } elseif ($customer_prices_in_post == true) {
		   $sppc_cg_products_price8_qty = $pInfo->sppcproducts_price8_qty[$customers_group['customers_group_id']];
	    } else {
		    $sppc_cg_products_price8_qty = ''; 
	    } 
	    echo tep_draw_input_field('sppcproducts_price8_qty[' . $customers_group['customers_group_id'] . ']', $sppc_cg_products_price8_qty, 'size="10"'); ?></td>
            </tr></table></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          </table>
          </div></div>
          </td></tr>
<?php
        } // end while ($customers_group = tep_db_fetch_array($customers_group_query))
?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
           
<!-- EOF Separate Pricing Per Customer -->
<!-- BOF SPPC hide from groups mod -->
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td colspan="2" class="maincol" ><?php echo TEXT_HIDE_PRODUCTS_FROM_GROUP; ?></td>
          </tr>
<?php   
   $hide_customers_group_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_id");
   $hide_from_groups_array = explode(',',$pInfo->products_hide_from_groups);
   $hide_from_groups_array = array_slice($hide_from_groups_array, 1); // remove "@" from the array
   while ($hide_customers_group = tep_db_fetch_array($hide_customers_group_query)) {
?>
      <tr bgcolor="#ebebff">
       <td class="maincol" colspan="2"><?php 
      if (isset($pInfo->hide)) {
	   echo tep_draw_checkbox_field('hide[' . $hide_customers_group['customers_group_id'] . ']',  $hide_customers_group['customers_group_id'] , (isset($pInfo->hide[ $hide_customers_group['customers_group_id']])) ? 1: 0);
      } else {
      echo tep_draw_checkbox_field('hide[' . $hide_customers_group['customers_group_id'] . ']',  $hide_customers_group['customers_group_id'] , (in_array($hide_customers_group['customers_group_id'], $hide_from_groups_array)) ? 1: 0);
      } ?>&#160;&#160;<?php echo $hide_customers_group['customers_group_name']; ?></td>
      </tr>
<?php
        } // end while ($hide_customers_group = tep_db_fetch_array($hide_customers_group_query))
?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
<!-- EOF Separate Pricing Per Customer -->


<?php
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
?>
          <tr>
            <td class="maincol" valign="top"><?php if ($i == 0) echo TEXT_PRODUCTS_DESCRIPTION; ?></td>
            <td><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              
                <td class="maincol" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
                <td class="maincol">
              <?php
					// parameters : areaname, content, hidden field, width, height, rows, cols
					editorArea( 'products_description[' . $languages[$i]['id'] . ']',  (isset($products_description[$languages[$i]['id']]) ? stripslashes($products_description[$languages[$i]['id']]) : tep_get_products_description($pInfo->products_id, $languages[$i]['id'])) , 'products_description[' . $languages[$i]['id'] . ']', '100%;', '300', '60', '20' ) ; ?></td></tr>
            </table></td>
          </tr>
<?php
    }
?>
<?php  //MVS start
 ?>
             <tr>
             <td class="maincol"><?php echo TEXT_VENDORS_PROD_COMMENTS; ?></td>
                <td class="maincol"><?php echo 

tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . 

tep_draw_textarea_field('vendors_prod_comments', 'soft', '70', '5', 

(isset($vendors_prod_comments) ? $vendors_prod_comments : 

tep_get_vendors_prod_comments($pInfo->products_id))); ?></td>
              </tr>
             <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', 

'1', '10'); ?></td>
            <?php  //MVS end
              ?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <?php //MVS start
           ?>
          <tr>
            <td class="maincol"><?php echo TEXT_VENDORS_PROD_ID; ?></td>
            <td class="maincol"><?php echo 

tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . 

tep_draw_input_field('vendors_prod_id', $pInfo->vendors_prod_id); ?></td>
          </tr>
          <?php     //MVS end
          ?>
          <tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_QUANTITY; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_quantity', $pInfo->products_quantity); ?></td>
</tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
		  <tr>
            <td class="maincol"><?php echo TEXT_Featured_Product;?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('Featured_Product', $pInfo->Featured_Product); ?></td>
          </tr>
          
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_MODEL; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_model', $pInfo->products_model); ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_IMAGE; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_file_field('products_image') . '<br>' . tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . $pInfo->products_image . tep_draw_hidden_field('products_previous_image', $pInfo->products_image); ?></td>
          </tr>
          <tr>
          <td class="maincol"><?php echo TEXT_PRODUCTS_PDFUPLOAD; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_file_field('products_pdfupload') . '<br>' . tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . $pInfo->products_pdfupload . tep_draw_hidden_field('products_previous_pdfupload', $pInfo->products_pdfupload); ?></td>
          </tr>
          <tr>
          <td class="maincol"><?php echo TEXT_PRODUCTS_VIDUPLOAD; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_file_field('products_vidupload') . '<br>' . tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . $pInfo->products_vidupload . tep_draw_hidden_field('products_previous_vidupload', $pInfo->products_vidupload); ?></td>
          </tr>
          <tr>
          <td class="maincol"><?php echo TEXT_PRODUCTS_FILEUPLOAD; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_file_field('products_fileupload') . '<br>' . tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . $pInfo->products_fileupload . tep_draw_hidden_field('products_previous_fileupload', $pInfo->products_fileupload); ?></td>
          </tr>
          <tr>
          <td class="maincol"><?php echo TEXT_PRODUCTS_MP3UPLOAD; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_file_field('products_mp3') . '<br>' . tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . $pInfo->products_mp3 . tep_draw_hidden_field('products_previous_mp3', $pInfo->products_mp3); ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
<?php
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
?>
          <tr>
            <td class="maincol"><?php if ($i == 0) echo TEXT_PRODUCTS_URL . '<br><small>' . TEXT_PRODUCTS_URL_WITHOUT_HTTP . '</small>'; ?></td>
            <td class="maincol"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('products_url[' . $languages[$i]['id'] . ']', (isset($products_url[$languages[$i]['id']]) ? stripslashes($products_url[$languages[$i]['id']]) : tep_get_products_url($pInfo->products_id, $languages[$i]['id']))); ?></td>
          </tr>
<?php
    }
?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_WEIGHT; ?></td>
            
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_weight', $pInfo->products_weight); ?></td>
          </tr>
          <tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_LENGTH; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_length', $pInfo->products_length); ?></td>
          </tr>
						<tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_WIDTH; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_width', $pInfo->products_width); ?></td>
          </tr>
						<tr>
            <td class="maincol"><?php echo TEXT_PRODUCTS_DEPTH; ?></td>
            <td class="maincol"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_depth', $pInfo->products_depth); ?></td>
          </tr>
          <?php
// START: Extra Fields Contribution (chapter 1.4)
      // Sort language by ID  
	  for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
	    $languages_array[$languages[$i]['id']]=$languages[$i];
	  }
      $extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_EXTRA_FIELDS . " ORDER BY products_extra_fields_order");
      while ($extra_fields = tep_db_fetch_array($extra_fields_query)) {
	  // Display language icon or blank space
        if ($extra_fields['languages_id']==0) {
	      $m=tep_draw_separator('pixel_trans.gif', '24', '15');
	    } else $m= tep_image(DIR_WS_CATALOG_LANGUAGES . $languages_array[$extra_fields['languages_id']]['directory'] . '/images/' . $languages_array[$extra_fields['languages_id']]['image'], $languages_array[$extra_fields['languages_id']]['name']);
?>
          <tr bgcolor="#ebebff">
            <td class="maincol"><?php echo $extra_fields['products_extra_fields_name']; ?>:</td>
            <td class="maincol"><?php echo $m . '&nbsp;' . tep_draw_input_field("extra_field[".$extra_fields['products_extra_fields_id']."]", $pInfo->extra_field[$extra_fields['products_extra_fields_id']]); ?></td>
          </tr>
<?php
}
// END: Extra Fields Contribution
?>

        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
       <?php
       show('doajaxattrib');


?>
<script language="javascript"><!--
goOnLoad();
//--></script>
      <tr>
        <td class="maincol" align="right"><?php echo tep_draw_hidden_field('products_date_added', (tep_not_null($pInfo->products_date_added) ? $pInfo->products_date_added : date('Y-m-d'))) . tep_image_submit('button_preview.gif', IMAGE_PREVIEW) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . (isset($_REQUEST['pID']) ? '&pID=' . $_REQUEST['pID'] : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
      </tr>
    </table></form>
<?php
  } elseif ($action == 'new_product_preview') {
    if (tep_not_null($_POST)) {
      $pInfo = new objectInfo($_POST);
      $products_name = $_POST['products_name'];
      $products_description = $_POST['products_description'];
      $products_url = $_POST['products_url'];
      
      $price_period = $_POST['price_period'];
      $oneday_price = $_POST['oneday_price'];
      $days_as_period = $_POST['days_as_period'];
      $pay_period_type = $_POST['pay_period_type'];

    } else {

      $product_query = tep_db_query("select p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_url, p.products_quantity, p.products_model, p.Featured_Product, p.vendors_prod_id, p.products_image, p.products_price, p.products_pdfupload, p.products_fileupload, p.products_vidupload, p.products_mp3,  p.products_price1, p.products_price2, p.products_price3, p.products_price4, p.products_price5, p.products_price6, p.products_price7, p.products_price8, p.products_price1_qty, p.products_price2_qty, p.products_price3_qty, p.products_price4_qty, p.products_price5_qty, p.products_price6_qty, p.products_price7_qty, p.products_price8_qty, p.products_qty_blocks, p.products_weight, p.products_date_added, p.products_last_modified, p.affiliate_allow_product, p.products_date_available, p.products_status, p.manufacturers_id, p.vendors_id, p.products_length, p.products_width, p.products_depth,p.suppliers_id, p.cost_price  from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . $_REQUEST['pID'] . "'");
      
      $product = tep_db_fetch_array($product_query);

      $pInfo = new objectInfo($product);
      $products_image_name = $pInfo->products_image;
    }

    $form_action = (isset($_REQUEST['pID'])) ? 'update_product' : 'insert_product';

    echo tep_draw_form($form_action, tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . (isset($_REQUEST['pID']) ? '&pID=' . $_REQUEST['pID'] : '') . '&action=' . $form_action), 'post', 'enctype="multipart/form-data"');

    $languages = tep_get_languages();
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
      if (isset($_REQUEST['read']) && ($_REQUEST['read'] == 'only')) {
        $pInfo->products_name = tep_get_products_name($pInfo->products_id, $languages[$i]['id']);
        $pInfo->products_description = tep_get_products_description($pInfo->products_id, $languages[$i]['id']);
        $pInfo->products_url = tep_get_products_url($pInfo->products_id, $languages[$i]['id']);
      } else {
        $pInfo->products_name = tep_db_prepare_input($products_name[$languages[$i]['id']]);
        $pInfo->products_description = tep_db_prepare_input($products_description[$languages[$i]['id']]);
        $pInfo->products_url = tep_db_prepare_input($products_url[$languages[$i]['id']]);
      }
?>
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . $pInfo->products_name; ?></td>
            <td class="pageHeading" align="right"><?php echo 

$currencies->format($pInfo->products_price);
            if ($pInfo->price_period !== '0.0000'){ 
if($pInfo->pay_period_type == 'By Period'){
if($pInfo->pay_period == ''){
$pt = "Every $pInfo->days_as_period days";
}else{
$pt = "Every $pInfo->pay_period days";
}
}else{
$pt = "$pInfo->pay_period_type";
}
echo'(setup fee)<br>+' . $currencies->format($pInfo->price_period) . '/' . $pt;
            } ?></td>
             <?php //MVS start
            ?>
            <td class="pageHeading" align="right"><?php echo "Vendor Price: 

<br>" . $currencies->format($pInfo->vendors_product_price); ?></td>
          </tr>
       <?php   //MVS end
       ?>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="maincol"><?php echo tep_image(DIR_WS_CATALOG_IMAGES . $products_image_name, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"');
         // START: Extra Fields Contribution (chapter 1.5)
          if ($_REQUEST['read'] == 'only') {
            $products_extra_fields_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE products_id=" . (int)$_REQUEST['pID']);
            while ($products_extra_fields = tep_db_fetch_array($products_extra_fields_query)) {
              $extra_fields_array[$products_extra_fields['products_extra_fields_id']] = $products_extra_fields['products_extra_fields_value'];
            }
          }
          else {
            $extra_fields_array = $_REQUEST['extra_field'];
          }

          $extra_fields_names_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_EXTRA_FIELDS. " WHERE languages_id='0' or languages_id='".(int)$languages[$i]['id']."' ORDER BY products_extra_fields_order");
          while ($extra_fields_names = tep_db_fetch_array($extra_fields_names_query)) {
            $extra_field_name[$extra_fields_names['products_extra_fields_id']] = $extra_fields_names['products_extra_fields_name'];
			echo '<B>'.$extra_fields_names['products_extra_fields_name'].':</B>&nbsp;'.stripslashes($extra_fields_array[$extra_fields_names['products_extra_fields_id']]).'<BR>'."\n";
          }		  
// END: Extra Fields Contribution


          echo "<br />"          . $pInfo->products_description; ?></td>
      </tr>
      <?php
      if($products_pdfupload_name != "") {
		?>
  <td class="main">
        <?php echo TEXT_PRODUCTS_PDFUPLOAD;?>
        PDF Uploaded</td>
      </tr>
      
  <?php
      }
      if($products_vidupload_name != "") {
		?>
  <td class="main">
        <?php echo TEXT_PRODUCTS_VIDUPLOAD;?>
        Video Uploaded</td>
      </tr>
      
  <?php
      }
      if($products_fileupload_name != "") {
		?>
  <td class="main">
        <?php echo TEXT_PRODUCTS_FILEUPLOAD;?>
        File Uploaded</td>
      </tr>
      
  <?php
      }
      if($products_mp3_name != "") {
		?>
  <td class="main">
        <?php echo TEXT_PRODUCTS_MP3UPLOAD;?>
        MP3 Uploaded</td>
      </tr>
      
  <?php
      }

      if ($pInfo->products_url) {
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="maincol"><?php echo sprintf(TEXT_PRODUCT_MORE_INFORMATION, $pInfo->products_url); ?></td>
      </tr>
<?php
      }
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
<?php
      if ($pInfo->products_date_available > date('Y-m-d')) {
?>
      <tr>
        <td align="center" class="smallText"><?php echo sprintf(TEXT_PRODUCT_DATE_AVAILABLE, tep_date_long($pInfo->products_date_available)); ?></td>
      </tr>
<?php
      } else {
?>
      <tr>
        <td align="center" class="smallText"><?php echo sprintf(TEXT_PRODUCT_DATE_ADDED, tep_date_long($pInfo->products_date_added)); ?></td>
      </tr>
<?php
      }
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
<?php
    }

    if (isset($_REQUEST['read']) && ($_REQUEST['read'] == 'only')) {
      if (isset($_REQUEST['origin'])) {
        $pos_params = strpos($_REQUEST['origin'], '?', 0);
        if ($pos_params != false) {
          $back_url = substr($_REQUEST['origin'], 0, $pos_params);
          $back_url_params = substr($_REQUEST['origin'], $pos_params + 1);
        } else {
          $back_url = $_REQUEST['origin'];
          $back_url_params = '';
        }
      } else {
        $back_url = FILENAME_CATEGORIES;
        $back_url_params = 'cPath=' . $cPath . '&pID=' . $pInfo->products_id;
      }
?>
      <tr>
        <td align="right"><?php echo '<a href="' . tep_href_link($back_url, $back_url_params, 'NONSSL') . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
      </tr>
<?php
    } else {
?>
      <tr>
        <td align="right" class="smallText">
<?php

      reset($_POST);
      while (list($key, $value) = each($_POST)) {
//        if (!is_array($_POST[$key])) {
	// BOF Separate Pricing per Customer
if (is_array($value)) {
  while (list($k, $v) = each($value)) {
  echo tep_draw_hidden_field($key . '[' . $k . ']', htmlspecialchars(stripslashes($v)));
  
  }
} else {
	// EOF Separate Pricing per Customer
	if ($key != 'osMod' && $key != 'CPath' && $key != 'action') {
          echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
          
          }
        }
      }
      $languages = tep_get_languages();
      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
        echo tep_draw_hidden_field('products_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_name[$languages[$i]['id']])));
        echo tep_draw_hidden_field('products_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_description[$languages[$i]['id']])));
        echo tep_draw_hidden_field('products_url[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_url[$languages[$i]['id']])));
      }
      
      // START: Extra Fields Contribution
      if ($_POST['extra_field']) { // Check to see if there are any need to update extra fields.
        foreach ($_POST['extra_field'] as $key=>$val) {
          echo tep_draw_hidden_field('extra_field['.$key.']', stripslashes($val));
        }
      } // Check to see if there are any need to update extra fields.
      // END: Extra Fields Contribution

      
      echo tep_draw_hidden_field('products_image', stripslashes($products_image_name));
      echo tep_draw_hidden_field('products_pdfupload', stripslashes($products_pdfupload_name));
      echo tep_draw_hidden_field('products_vidupload', stripslashes($products_vidupload_name));
      echo tep_draw_hidden_field('products_fileupload', stripslashes($products_fileupload_name));
      echo tep_draw_hidden_field('products_mp3', stripslashes($products_mp3_name));

      echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . '&nbsp;&nbsp;';

      if (isset($_REQUEST['pID'])) {
        echo tep_image_submit('button_update.gif', IMAGE_UPDATE);
      } else {
        echo tep_image_submit('button_insert.gif', IMAGE_INSERT);
      }
      echo '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . (isset($_REQUEST['pID']) ? '&pID=' . $_REQUEST['pID'] : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
?></td>
      </tr>
    </table></form>
<?php
    }
    
  } else {
?>
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
            <td align="right"><table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td class="smallText" align="right">
<?php
    echo tep_draw_form('search', tep_href_link(FILENAME_CATEGORIES, ''), 'get');
    echo HEADING_TITLE_SEARCH . ' ' . tep_draw_input_field('search');
    echo tep_hide_session_id() . '</form>';
?>
                </td>
              </tr>
              <tr>
                <td class="smallText" align="right">
<?php
    echo tep_draw_form('goto', tep_href_link(FILENAME_CATEGORIES, ''), 'get');
    echo HEADING_TITLE_GOTO . ' ' . tep_draw_pull_down_menu('cPath', tep_get_category_tree(), $current_category_id, 'onChange="this.form.submit();"');
    echo tep_hide_session_id() . '</form>';
?>
                </td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2" class="adminlist"><thead>
              <tr class="dataTableHeadingRow">
                <th class="dataTableHeadingContent"><?php echo TABLE_HEADING_CATEGORIES_PRODUCTS; ?></td>
                <th class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_HIDE_CATEGORIES; ?></td>
                <th class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_STATUS; ?></td>
                
                <th class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr></thead>
<?php

     $categories_count = 0;
    $rows = 0;
// BOF SPPC hide products and categories from groups
    $customers_group_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_id");
    while ($customer_groups = tep_db_fetch_array($customers_group_query)) {
      $customers_groups[] = array('id' => $customer_groups['customers_group_id'], 'text' => $customer_groups['customers_group_name']);  
    }
    if (isset($_GET['search'])) {
      $search = tep_db_prepare_input($_GET['search']);
      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, cd.categories_description, c.categories_image, c.parent_id, c.sort_order, c.date_added, c.last_modified, c.categories_hide_from_groups from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and cd.categories_name like '%" . tep_db_input($search) . "%' order by c.sort_order, cd.categories_name");
    } else {
      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, cd.categories_description, c.categories_image, c.parent_id, c.sort_order, c.date_added, c.last_modified, c.categories_hide_from_groups from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by c.sort_order, cd.categories_name");
    }

    
// EOF SPPC hide products and categories from groups
    while ($categories = tep_db_fetch_array($categories_query)) {
      $categories_count++;
      $rows++;

// Get parent_id for subcategories if search
      if (isset($_REQUEST['search'])) $cPath= $categories['parent_id'];

      if ((!isset($_REQUEST['cID']) && !isset($_REQUEST['pID']) || (isset($_REQUEST['cID']) && ($_REQUEST['cID'] == $categories['categories_id']))) && !isset($cInfo) && (substr($action, 0, 3) != 'new')) {
        $category_childs = array('childs_count' => tep_childs_in_category_count($categories['categories_id']));
        $category_products = array('products_count' => tep_products_in_category_count($categories['categories_id']));

        $cInfo_array = array_merge($categories, $category_childs, $category_products);
        $cInfo = new objectInfo($cInfo_array);
      }

      if (isset($cInfo) && is_object($cInfo) && ($categories['categories_id'] == $cInfo->categories_id) ) {
        echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CATEGORIES, tep_get_path($categories['categories_id'])) . '\'">' . "\n";
      } else {
        echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories['categories_id']) . '\'">' . "\n";
      }
?>
                <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, tep_get_path($categories['categories_id'])) . '">' . tep_image(DIR_WS_ICONS . 'folder.gif', ICON_FOLDER) . '</a>&nbsp;<b>' . $categories['categories_name'] . '</b>'; ?></td> 
                
              
                <?php // BOF SPPC hide products and categories from groups ?>
		<td class="dataTableContent" align="center"><?php
    $hide_cat_from_groups_array = explode(',', $categories['categories_hide_from_groups']);
    $hide_cat_from_groups_array = array_slice($hide_cat_from_groups_array, 1); // remove "@" from the array
	$category_hidden_from_string = '';
	if (LAYOUT_HIDE_FROM == '1') {
	      for ($i = 0; $i < count($customers_groups); $i++) {
		      if (in_array($customers_groups[$i]['id'], $hide_cat_from_groups_array)) {
	        $category_hidden_from_string .= $customers_groups[$i]['text'] . ', '; 
		      }
              } // end for ($i = 0; $i < count($customers_groups); $i++)
	      $category_hidden_from_string = rtrim($category_hidden_from_string); // remove space on the right
	      $category_hidden_from_string = substr($category_hidden_from_string,0,strlen($category_hidden_from_string) -1); // remove last comma
	      if (!tep_not_null($category_hidden_from_string)) { 
	      $category_hidden_from_string = TEXT_GROUPS_NONE; 
	      }
	      $category_hidden_from_string = TEXT_HIDDEN_FROM_GROUPS . $category_hidden_from_string;
				// if the string in the database field is @, everything will work fine, however tep_not_null
				// will not discover the associative array is empty therefore the second check on the value
	if (tep_not_null($hide_cat_from_groups_array) && tep_not_null($hide_cat_from_groups_array[0])) {
		  echo tep_image(DIR_WS_ICONS . 'tick_black.gif', $category_hidden_from_string, 20, 16);
		} else {
		  echo tep_image(DIR_WS_IMAGES . 'pixel_trans.gif', $category_hidden_from_string, 20, 16);
	  }
	} else {
		// default layout: icons for all groups
      for ($i = 0; $i < count($customers_groups); $i++) {
        if (in_array($customers_groups[$i]['id'], $hide_cat_from_groups_array)) {
          echo tep_image(DIR_WS_ICONS . 'icon_tick.gif', $customers_groups[$i]['text'], 11, 11) . '&nbsp;&nbsp;';
        } else {
          echo tep_image(DIR_WS_IMAGES . 'pixel_trans.gif', '', 11, 11) . '&nbsp;&nbsp;';
        }
      }
	}
?></td><?php // EOF SPPC hide products and categories from groups ?>
                <td class="dataTableContent" align="center">&nbsp;</td>
                <td class="dataTableContent" align="right"><?php if (isset($cInfo) && is_object($cInfo) && ($categories['categories_id'] == $cInfo->categories_id) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories['categories_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
<?php
    }

    $products_count = 0;
    if (isset($_REQUEST['search'])) {
    
      $prod_sql = "select p.products_id, pd.products_name, p.products_quantity, p.cost_price, p.suppliers_id, p.products_image, p.products_price, p.products_pdfupload, p.products_fileupload, p.products_vidupload, p.products_mp3,  p.products_price1, p.products_price2, p.products_price3, p.products_price4, p.products_price5, p.products_price6, p.products_price7, p.products_price8, p.products_price1_qty, p.products_price2_qty, p.products_price3_qty, p.products_price4_qty, p.products_price5_qty, p.products_price6_qty, p.products_price7_qty, p.products_price8_qty, p.products_qty_blocks,  p.vendors_product_price, p.vendors_prod_comments, p.products_date_added, p.affiliate_allow_product, p.products_last_modified, p.products_date_available, p.products_status, p.products_hide_from_groups, p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and pd.products_name like '%" . tep_db_input($search) . "%' order by pd.products_name";
    } else {
      $prod_sql = "select p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_pdfupload, p.products_fileupload, p.products_vidupload, p.products_mp3, p.cost_price,  p.products_price1, p.products_price2, p.products_price3, p.products_price4, p.products_price5, p.products_price6, p.products_price7, p.products_price8, p.products_price1_qty, p.products_price2_qty, p.products_price3_qty, p.products_price4_qty, p.products_price5_qty, p.products_price6_qty, p.products_price7_qty, p.products_price8_qty, p.products_qty_blocks, p.suppliers_id, p.products_price, p.vendors_product_price, p.vendors_prod_comments, p.products_date_added, p.affiliate_allow_product, p.products_last_modified, p.products_date_available, p.products_status, p.products_hide_from_groups from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by pd.products_name";

    }
    
    $prod_split = new splitPageResults($_GET['page'], MAX_PROD_ADMIN_SIDE, $prod_sql, $prod_query_numrows);
    $products_query = tep_db_query($prod_sql);
    while ($products = tep_db_fetch_array($products_query)) {
      $products_count++;
      $rows++;

// Get categories_id for product if search
      if (isset($_REQUEST['search'])) $cPath = $products['categories_id'];

      if ( (!isset($_REQUEST['pID']) && !isset($_REQUEST['cID']) || (isset($_REQUEST['pID']) && ($_REQUEST['pID'] == $products['products_id']))) && !isset($pInfo) && !isset($cInfo) && (substr($action, 0, 3) != 'new')) {
// find out the rating average from customer reviews
        $reviews_query = tep_db_query("select (avg(reviews_rating) / 5 * 100) as average_rating from " . TABLE_REVIEWS . " where products_id = '" . (int)$products['products_id'] . "'");
        $reviews = tep_db_fetch_array($reviews_query);
        $pInfo_array = array_merge($products, $reviews);
        $pInfo = new objectInfo($pInfo_array);
      }

      if (isset($pInfo) && is_object($pInfo) && ($products['products_id'] == $pInfo->products_id) ) {
        echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products['products_id'] . '&action=new_product_preview&read=only') . '\'">' . "\n";
      } else {
        echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products['products_id']) . '&page='.$HTTP_GET_VARS['page'].'\'">' . "\n";
      }
?>
                <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products['products_id'] . '&action=new_product_preview&read=only') . '">' . tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '</a>&nbsp;' . $products['products_name']; ?></td>
                <?php  //BOF SPPC hide products and categories from groups ?>
		<td class="dataTableContent" align="center"><?php
    $hide_prods_from_groups_array = explode(',', $products['products_hide_from_groups']);
    $hide_prods_from_groups_array = array_slice($hide_prods_from_groups_array, 1); // remove "@" from the array
		if (LAYOUT_HIDE_FROM == '1') {
	$product_hidden_from_string = '';
	      for ($i = 0; $i < count($customers_groups); $i++) {
		      if (in_array($customers_groups[$i]['id'], $hide_prods_from_groups_array)) {
	        $product_hidden_from_string .= $customers_groups[$i]['text'] . ', '; 
		      }
              } // end for ($i = 0; $i < count($customers_groups); $i++)
	      $product_hidden_from_string = rtrim($product_hidden_from_string); // remove space on the right
	      $product_hidden_from_string = substr($product_hidden_from_string,0,strlen($product_hidden_from_string) -1); // remove last comma
	if (tep_not_null($hide_prods_from_groups_array)&& tep_not_null($hide_prods_from_groups_array[0])) { 
	      $product_hidden_from_string = TEXT_GROUPS_NONE; 
	      }
	      $product_hidden_from_string = TEXT_HIDDEN_FROM_GROUPS . $product_hidden_from_string;
	if (tep_not_null($hide_prods_from_groups_array)) {
		  echo tep_image(DIR_WS_ICONS . 'tick_black.gif', $product_hidden_from_string, 20, 16);
		} else {
		  echo tep_image(DIR_WS_IMAGES . 'pixel_trans.gif', $product_hidden_from_string, 20, 16);
	  }
	} else {
		// default layout: icons for all groups
      for ($i = 0; $i < count($customers_groups); $i++) {
        if (in_array($customers_groups[$i]['id'], $hide_prods_from_groups_array)) {
          echo tep_image(DIR_WS_ICONS . 'icon_tick.gif', $customers_groups[$i]['text'], 11, 11) . '&nbsp;&nbsp;';
        } else {
          echo tep_image(DIR_WS_IMAGES . 'pixel_trans.gif', '', 11, 11) . '&nbsp;&nbsp;';
        }
      }
	} // end if/else (LAYOUT_HIDE_FROM == '1')
?></td><?php // EOF SPPC hide products and categories from groups ?>
                
                <td class="dataTableContent" align="center">
<?php
      if ($products['products_status'] == '1') {
        echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=0&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
      } else {
        echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=1&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10);
      }
?></td>
                <td class="dataTableContent" align="right"><?php if (isset($pInfo) && is_object($pInfo) && ($products['products_id'] == $pInfo->products_id)) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&page='.$HTTP_GET_VARS['page'] . '&pID=' . $products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
<?php
    }

    $cPath_back = '';
    if (sizeof($cPath_array) > 0) {
      for ($i=0, $n=sizeof($cPath_array)-1; $i<$n; $i++) {
        if (empty($cPath_back)) {
          $cPath_back .= $cPath_array[$i];
        } else {
          $cPath_back .= '_' . $cPath_array[$i];
        }
      }
    }

    $cPath_back = (tep_not_null($cPath_back)) ? 'cPath=' . $cPath_back . '&' : '';
?>
<tr>
                <td colspan="4">
                  <table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText" valign="top"><?php echo $prod_split->display_count($prod_query_numrows, MAX_PROD_ADMIN_SIDE, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
                    <td class="smallText" align="right"><?php echo $prod_split->display_links($prod_query_numrows, MAX_PROD_ADMIN_SIDE, MAX_DISPLAY_PAGE_LINKS, $_GET['page'], tep_get_all_get_params(array('page'))); ?></td>                    
                  </tr>                  
                  </table> 
                </td>
              </td>
              <tr>
                <td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText"><?php echo TEXT_CATEGORIES . '&nbsp;' . $categories_count . '<br>' . TEXT_PRODUCTS . '&nbsp;' . $products_count; ?></td>
                    <td align="right" class="smallText"><?php if (sizeof($cPath_array) > 0) echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, $cPath_back . 'cID=' . $current_category_id) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>&nbsp;'; if (!isset($_REQUEST['search'])) echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&action=new_category') . '">' . tep_image_button('button_new_category.gif', IMAGE_NEW_CATEGORY) . '</a>&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&action=new_product') . '">' . tep_image_button('button_new_product.gif', IMAGE_NEW_PRODUCT) . '</a>'; ?>&nbsp;</td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
<?php
    $heading = array();
    $contents = array();
    // BOF SPPC hide products and categories from groups
    $hide_cat_from_groups_array = explode(',',$cInfo->categories_hide_from_groups);
    $hide_cat_from_groups_array = array_slice($hide_cat_from_groups_array, 1); // remove "@" from the array
		$hide_product_from_groups_array = explode(',',$pInfo->products_hide_from_groups);
    $hide_product_from_groups_array = array_slice($hide_product_from_groups_array, 1); // remove "@" from the array
// EOF SPPC hide products and categories from groups
    switch ($action) {
      case 'new_category':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_CATEGORY . '</b>');

        $contents = array('form' => tep_draw_form('newcategory', tep_href_link(FILENAME_CATEGORIES, 'action=insert_category&cPath=' . $cPath), 'post', 'enctype="multipart/form-data"'));
        $contents[] = array('text' => TEXT_NEW_CATEGORY_INTRO);

        $category_inputs_string = '';
        $languages = tep_get_languages();
        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
          $category_inputs_string .= '<br>' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('categories_name[' . $languages[$i]['id'] . ']');
        }
        
        $category_desc_inputs_string = '';
        $languages = tep_get_languages();
        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
          $category_desc_inputs_string .= '<br>' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_textarea_field('categories_description[' . $languages[$i]['id'] . ']', '', 20, 5);
        }

        $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_NAME . $category_inputs_string);
         $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_DESC . $category_desc_inputs_string);
        $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('categories_image'));
        $contents[] = array('text' => '<br>' . TEXT_SORT_ORDER . '<br>' . tep_draw_input_field('sort_order', '', 'size="2"'));
        // BOF SPPC hide products and categories from groups
        $category_hide_string = '<br>'. "\n" . TEXT_HIDE_CATEGORIES_FROM_GROUPS;
         for ($i = 0; $i < count($customers_groups); $i++) {
	   $category_hide_string .= '<br>' . "\n" . tep_draw_checkbox_field('hide_cat[' . $customers_groups[$i]['id'] . ']',  $customers_groups[$i]['id'] , 0) . '&#160;&#160;' . $customers_groups[$i]['text']; 
          }
        $contents[] = array('text' => $category_hide_string);
// EOF SPPC hide products and categories from groups

        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_SAVE) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'edit_category':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_EDIT_CATEGORY . '</b>');

        $contents = array('form' => tep_draw_form('categories', tep_href_link(FILENAME_CATEGORIES, 'action=update_category&cPath=' . $cPath), 'post', 'enctype="multipart/form-data"') . tep_draw_hidden_field('categories_id', $cInfo->categories_id));
        $contents[] = array('text' => TEXT_EDIT_INTRO);

        $category_inputs_string = '';
        $languages = tep_get_languages();
        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
          $category_inputs_string .= '<br>' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('categories_name[' . $languages[$i]['id'] . ']', tep_get_category_name($cInfo->categories_id, $languages[$i]['id']));
        }
        $category_desc_inputs_string = '';
        $languages = tep_get_languages();
        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
          $category_desc_inputs_string .= '<br>' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_textarea_field('categories_description[' . $languages[$i]['id'] . ']', '', 20, 5, tep_get_category_description($cInfo->categories_id, $languages[$i]['id']));
        }


        $contents[] = array('text' => '<br>' . TEXT_EDIT_CATEGORIES_NAME . $category_inputs_string);
        $contents[] = array('text' => '<br>' . TEXT_CATEGORIES_DESC . $category_desc_inputs_string);
        $contents[] = array('text' => '<br>' . tep_image(DIR_WS_CATALOG_IMAGES . $cInfo->categories_image, $cInfo->categories_name) . '<br>' . DIR_WS_CATALOG_IMAGES . '<br><b>' . $cInfo->categories_image . '</b>');
        $contents[] = array('text' => '<br>' . TEXT_EDIT_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('categories_image'));
        $contents[] = array('text' => '<br>' . TEXT_EDIT_SORT_ORDER . '<br>' . tep_draw_input_field('sort_order', $cInfo->sort_order, 'size="2"'));
        // BOF SPPC hide products and categories from groups
        $category_hide_string = '<br>'. "\n" . TEXT_HIDE_CATEGORIES_FROM_GROUPS;
         for ($i = 0; $i < count($customers_groups); $i++) {
	   $category_hide_string .= '<br>' . "\n" . tep_draw_checkbox_field('hide_cat[' . $customers_groups[$i]['id'] . ']',  $customers_groups[$i]['id'] , (in_array($customers_groups[$i]['id'], $hide_cat_from_groups_array)) ? 1: 0) . '&#160;&#160;' . $customers_groups[$i]['text']; 
          }
        $contents[] = array('text' => $category_hide_string);
// EOF SPPC hide products and categories from groups
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_SAVE) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $cInfo->categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'delete_category':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_CATEGORY . '</b>');

        $contents = array('form' => tep_draw_form('categories', tep_href_link(FILENAME_CATEGORIES, 'action=delete_category_confirm&cPath=' . $cPath)) . tep_draw_hidden_field('categories_id', $cInfo->categories_id));
        $contents[] = array('text' => TEXT_DELETE_CATEGORY_INTRO);
        $contents[] = array('text' => '<br><b>' . $cInfo->categories_name . '</b>');
        if ($cInfo->childs_count > 0) $contents[] = array('text' => '<br>' . sprintf(TEXT_DELETE_WARNING_CHILDS, $cInfo->childs_count));
        if ($cInfo->products_count > 0) $contents[] = array('text' => '<br>' . sprintf(TEXT_DELETE_WARNING_PRODUCTS, $cInfo->products_count));
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $cInfo->categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'move_category':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_MOVE_CATEGORY . '</b>');

        $contents = array('form' => tep_draw_form('categories', tep_href_link(FILENAME_CATEGORIES, 'action=move_category_confirm&cPath=' . $cPath)) . tep_draw_hidden_field('categories_id', $cInfo->categories_id));
        $contents[] = array('text' => sprintf(TEXT_MOVE_CATEGORIES_INTRO, $cInfo->categories_name));
        $contents[] = array('text' => '<br>' . sprintf(TEXT_MOVE, $cInfo->categories_name) . '<br>' . tep_draw_pull_down_menu('move_to_category_id', tep_get_category_tree(), $current_category_id));
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_move.gif', IMAGE_MOVE) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $cInfo->categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'delete_product':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_PRODUCT . '</b>');

        $contents = array('form' => tep_draw_form('products', tep_href_link(FILENAME_CATEGORIES, 'action=delete_product_confirm&cPath=' . $cPath)) . tep_draw_hidden_field('products_id', $pInfo->products_id));
        $contents[] = array('text' => TEXT_DELETE_PRODUCT_INTRO);
        $contents[] = array('text' => '<br><b>' . $pInfo->products_name . '</b>');

        $product_categories_string = '';
        $product_categories = tep_generate_category_path($pInfo->products_id, 'product');
        for ($i = 0, $n = sizeof($product_categories); $i < $n; $i++) {
          $category_path = '';
          for ($j = 0, $k = sizeof($product_categories[$i]); $j < $k; $j++) {
            $category_path .= $product_categories[$i][$j]['text'] . '&nbsp;&gt;&nbsp;';
          }
          $category_path = substr($category_path, 0, -16);
          $product_categories_string .= tep_draw_checkbox_field('product_categories[]', $product_categories[$i][sizeof($product_categories[$i])-1]['id'], true) . '&nbsp;' . $category_path . '<br>';
        }
        $product_categories_string = substr($product_categories_string, 0, -4);

        $contents[] = array('text' => '<br>' . $product_categories_string);
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'move_product':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_MOVE_PRODUCT . '</b>');

        $contents = array('form' => tep_draw_form('products', tep_href_link(FILENAME_CATEGORIES, 'action=move_product_confirm&cPath=' . $cPath)) . tep_draw_hidden_field('products_id', $pInfo->products_id));
        $contents[] = array('text' => sprintf(TEXT_MOVE_PRODUCTS_INTRO, $pInfo->products_name));
        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENT_CATEGORIES . '<br><b>' . tep_output_generated_category_path($pInfo->products_id, 'product') . '</b>');
        $contents[] = array('text' => '<br>' . sprintf(TEXT_MOVE, $pInfo->products_name) . '<br>' . tep_draw_pull_down_menu('move_to_category_id', tep_get_category_tree(), $current_category_id));
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_move.gif', IMAGE_MOVE) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      case 'copy_to':
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_COPY_TO . '</b>');

        $contents = array('form' => tep_draw_form('copy_to', tep_href_link(FILENAME_CATEGORIES, 'action=copy_to_confirm&cPath=' . $cPath)) . tep_draw_hidden_field('products_id', $pInfo->products_id));
        $contents[] = array('text' => TEXT_INFO_COPY_TO_INTRO);
        $contents[] = array('text' => '<br>' . TEXT_INFO_CURRENT_CATEGORIES . '<br><b>' . tep_output_generated_category_path($pInfo->products_id, 'product') . '</b>');
        $contents[] = array('text' => '<br>' . TEXT_CATEGORIES . '<br>' . tep_draw_pull_down_menu('categories_id', tep_get_category_tree(), $current_category_id));
        $contents[] = array('text' => '<br>' . TEXT_HOW_TO_COPY . '<br>' . tep_draw_radio_field('copy_as', 'link', true) . ' ' . TEXT_COPY_AS_LINK . '<br>' . tep_draw_radio_field('copy_as', 'duplicate') . ' ' . TEXT_COPY_AS_DUPLICATE);
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_copy.gif', IMAGE_COPY) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
        break;
      default:
      function subscrit($price,$period){
      $scrit = "(setup fee)<br>+$$price / $period";
      return $scrit;
      }
      define ('TEXT_SUBINFO','(setup fee)<br>+$$pInfo->price_period/$pInfo->pay_period_type');
        if ($rows > 0) {
          if (isset($cInfo) && is_object($cInfo)) { // category info box contents
          $category_path_string = ''; 
              $category_path = tep_generate_category_path($cInfo->categories_id); 
              for ($i=(sizeof($category_path[0])-1); $i>0; $i--) { 
                 $category_path_string .= $category_path[0][$i]['id'] . '_'; 
               } 
               $category_path_string = substr($category_path_string, 0, -1); 

          
            $heading[] = array('text' => '<b>' . $cInfo->categories_name . '</b>');

        
            $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=edit_category') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=delete_category') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a> <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=move_category') . '">' . tep_image_button('button_move.gif', IMAGE_MOVE) . '</a>');
            
            $contents[] = array('text' => '<br>' . TEXT_DATE_ADDED . ' ' . tep_date_short($cInfo->date_added));
            if (tep_not_null($cInfo->last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . tep_date_short($cInfo->last_modified));
            $contents[] = array('text' => '<br>' . tep_info_image($cInfo->categories_image, $cInfo->categories_name, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT) . '<br>' . $cInfo->categories_image);
            $contents[] = array('text' => '<br>' . TEXT_SUBCATEGORIES . ' ' . $cInfo->childs_count . '<br>' . TEXT_PRODUCTS . ' ' . $cInfo->products_count);
            // BOF SPPC hide products and categories from groups
	    $category_hidden_from_string = '';
	      for ($i = 0; $i < count($customers_groups); $i++) {
		      if (in_array($customers_groups[$i]['id'], $hide_cat_from_groups_array)) {
	        $category_hidden_from_string .= $customers_groups[$i]['text'] . ', '; 
		      }
              } // end for ($i = 0; $i < count($customers_groups); $i++)
	      $category_hidden_from_string = rtrim($category_hidden_from_string); // remove space on the right
	      $category_hidden_from_string = substr($category_hidden_from_string,0,strlen($category_hidden_from_string) -1); // remove last comma
	      if (!tep_not_null($category_hidden_from_string)) { 
	      $category_hidden_from_string = TEXT_GROUPS_NONE; 
	      }
	      $category_hidden_from_string = '<br>'. "\n" . TEXT_HIDDEN_FROM_GROUPS . $category_hidden_from_string;
	    $contents[] = array('text' => $category_hidden_from_string);
// EOF SPPC hide products and categories from groups
          } elseif (isset($pInfo) && is_object($pInfo)) { // product info box contents
           //MVS start
    $vendors_query_2 = tep_db_query("select v.vendors_id, v.vendors_name from " . TABLE_VENDORS ." v, ". TABLE_PRODUCTS ." p where v.vendors_id=p.vendors_id and 

p.products_id='" . $pInfo->products_id . "'");
    while ($vendors_2 = tep_db_fetch_array($vendors_query_2)) {
            $current_vendor_name = $vendors_2['vendors_name'];
    }     // MVS end
            $heading[] = array('text' => '<b>' . tep_get_products_name($pInfo->products_id, $languages_id) . '</b>');

            $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=delete_product') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a> <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=move_product') . '">' . tep_image_button('button_move.gif', IMAGE_MOVE) . '</a> <a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=copy_to') . '">' . tep_image_button('button_copy_to.gif', IMAGE_COPY_TO) . '</a>');
            $contents[] = array('text' => '<br>' . TEXT_DATE_ADDED . ' ' . tep_date_short($pInfo->products_date_added));
            if (tep_not_null($pInfo->products_last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . tep_date_short($pInfo->products_last_modified));
            if (date('Y-m-d') < $pInfo->products_date_available) $contents[] = array('text' => TEXT_DATE_AVAILABLE . ' ' . tep_date_short($pInfo->products_date_available));
            $contents[] = array('text' => '<br>' . tep_info_image($pInfo->products_image, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br>' . $pInfo->products_image);
               $suppliers_products_query = tep_db_query("select p.suppliers_id, p.cost_price, s.suppliers_id, s.suppliers_percentage from " . TABLE_PRODUCTS . " p, " . TABLE_SUPPLIERS . " s where p.suppliers_id = s.suppliers_id and p.suppliers_id = '" . (int)$pInfo->suppliers_id . "'");
              $suppliers_products = tep_db_fetch_array($suppliers_products_query);
        if ( $pInfo->cost_price > 0 ){

                                    $suppliers_percentage = $suppliers_products['suppliers_percentage'];

                                    $suppliers_percentage = $suppliers_percentage / 100;

           } 

            
            //MVS start
            if ($pInfo->price_period) $contents[] = array('text' => ' ' . subscrit($pInfo->price_period, $pInfo->pay_period_type));
            $contents[] = array('text' => '<br>' . TEXT_PRODUCTS_PRICE_INFO 

. '<b> ' . $currencies->format($pInfo->products_price) . '</b><br>Vendor:  

<b>' . $current_vendor_name . '</b><br>' . TEXT_VENDORS_PRODUCT_PRICE_INFO . 

'<b>' . $currencies->format($pInfo->vendors_product_price) . '</b><br>' . 

TEXT_PRODUCTS_QUANTITY_INFO . ' <b>' . $pInfo->products_quantity . '</b>');
     //MVS end  thats the last mod for this file
            $contents[] = array('text' => '<br>' . TEXT_PRODUCTS_AVERAGE_RATING . ' ' . number_format($pInfo->average_rating, 2) . '%');
            // BOF SPPC hide products and categories from groups
	    $product_hidden_from_string = '';
	      for ($i = 0; $i < count($customers_groups); $i++) {
		      if (in_array($customers_groups[$i]['id'], $hide_product_from_groups_array)) {
	        $product_hidden_from_string .= $customers_groups[$i]['text'] . ', '; 
		      }
              } // end for ($i = 0; $i < count($customers_groups); $i++)
	      $product_hidden_from_string = rtrim($product_hidden_from_string); // remove space on the right
	      $product_hidden_from_string = substr($product_hidden_from_string,0,strlen($product_hidden_from_string) -1); // remove last comma
	      if (!tep_not_null($product_hidden_from_string)) { 
	      $product_hidden_from_string = TEXT_GROUPS_NONE; 
	      }
	      $product_hidden_from_string = '<br>'. "\n" . TEXT_HIDDEN_FROM_GROUPS . $product_hidden_from_string;
	    $contents[] = array('text' => $product_hidden_from_string);
// EOF SPPC hide products and categories from groups
          }
        } else { // create category/product info
          $heading[] = array('text' => '<b>' . EMPTY_CATEGORY . '</b>');

          $contents[] = array('text' => TEXT_NO_CHILD_CATEGORIES_OR_PRODUCTS);
        }
        break;
    }

    if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
      echo '            <td width="25%" valign="top">' . "\n";

      $box = new box;
      echo $box->infoBox($heading, $contents);

      echo '            </td>' . "\n";
    }
?>
          </tr>
        </table></td>
      </tr>
    </table>
<?php
  }
?>
    </td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->

<?php
  require(DIR_WS_INCLUDES . 'application_bottom.php');

  // -- webMS Modification --
  // reset the Mambo Database connection (stomped by osCommerce Connection)
  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
?>
